Reputation: 99
I am trying to upload an image in Laravel 5.
My environment is Windows. I am using php artisan serve to run Laravel.
Error:
NotWritableException in Image.php line 143:
Can't write image data to path (D:\WORK\WebSite\iStore\public\assets/images/products/2015-07-05-08:52:33-6aa3df83gw1dtd5qki2oij.jpg)
Controller:
$image = Input::file('image');
$filename = date('Y-m-d-H:i:s') . "-" . $image->getClientOriginalName();
$path = public_path('assets/images/products/' . $filename);
// echo dd(is_writable(public_path('assets/images/products')));
Image::make($image->getRealPath())-> resize(200, 200)-> save($path);
$product->image = 'assets/images/products/' . $filename;
I used dd(is_writable())to check permission, it is true.
And I also try
chmod 777 public/assets/images/products
View:
{!! Form::open(array('url' => 'admin/product/update', 'class' => '', 'files' => true)) !!}
<div class="form-group">
{!! Form::Label('image', 'Product Image', array('sr-only')) !!}
<div>
{!! HTML::image($product->image, $product->title, array('class' => 'img-rounded', 'height' => '200')) !!}
</div>
<hr/>
{!! Form::file('image', array('class' => 'form-group')) !!}
</div>
{!! Form::close() !!}
What can I do with this error?
Upvotes: 2
Views: 2129
Reputation: 44566
You problem might lie with the fact that you are using reserved characters within your file name. In Windows you cannot use colons :
in file names. So you might want to replace the colons with dashes or something else, maybe like so:
$filename = date('Y-m-d_H-i-s') . "-" . $image->getClientOriginalName();
If readability is not a requirement here, and you're using the date and time to create unique filenames, you could just prepend a UNIX timestamp to the filename:
$filename = time() . "-" . $image->getClientOriginalName();
You might want to read the Naming Files, Paths, and Namespaces documentation on MSDN for more information about the subject.
Upvotes: 0
Reputation: 11310
Make sure that the Folder you mentioned i.e., assets/images/products/
exists and it has writable permission
Make sure that you have a good file name i.e., it should not contain :
symbol
So you shall change you code like this
$image = Input::file('image');
$filename = date('Y-m-d-H-i-s')."-". $image->getClientOriginalName();
$path = public_path('assets/images/products/'.$filename);
Image::make($image->getRealPath())-> resize(200, 200)-> save($path);
Upvotes: 1