Page 1 of 1
change backslash to forwardslash using the public_path
Posted: Thu Oct 08, 2015 10:11 am
by gautamz07
I am using the IMAGINE
https://github.com/orchestral/imagine package in laravel , I have the below line in laravel:
Code: Select all
$path = public_path('img\testsave\/' .$filename);
now I'm getting the following error:
Code: Select all
C:\xampp\htdocs\lookinggood\public/img\testsave/2015-10-07-11-40-19-edit-one.jpgjpg does not exist.
Code: Select all
The backslash after public needs to be changed to a forward slash. After testsave I am getting the \/ .
I have tried to escape the forward slash like so:
Code: Select all
$path = public_path('img\testsave\/' .$filename);
So how do I change the backslash after public to a forwardslash and how do I successfully escape the forward slash after testsave ?
Re: change backslash to forwardslash using the public_path
Posted: Thu Oct 08, 2015 9:36 pm
by Christopher
I think you should use only forward slashes. PHP makes them work on windows. If you mix them it gets confused.
Re: change backslash to forwardslash using the public_path
Posted: Fri Oct 09, 2015 4:54 am
by gautamz07
even if i change my code to the below ,
Code: Select all
$path = public_path("img/testsave/" .$filename);
I still get an error as follows:
http://i.imgur.com/42wf5PC.jpg
Re: change backslash to forwardslash using the public_path
Posted: Fri Oct 09, 2015 4:58 am
by gautamz07
i know that windows does't really bother weather its a forward or a backslash.
Re: change backslash to forwardslash using the public_path
Posted: Fri Oct 09, 2015 6:14 am
by Celauran
What's the other code surrounding that? Have you check that the file does in fact exist?
Re: change backslash to forwardslash using the public_path
Posted: Fri Oct 09, 2015 8:36 am
by gautamz07
What's the other code surrounding that?
The entire code is as below:
Code: Select all
public function postCreate() {
$fileupload = new Fileupload;
$height = 200;
$width = 400;
$mode = ImageInterface::THUMBNAIL_OUTBOUND;
$size = new Box($width, $height);
$image = Input::file('image');
$filename = date('Y-m-d-H-i-s')."-".$image->getClientOriginalName();
$path = public_path("img/testsave/" .$filename);
$thumbnail = Imagine::open($path)->thumbnail($size);
$fileupload->save();
return Redirect::to('admin/products/index')
->with('message' , 'Product created');
}
Have you check that the file does in fact exist?
Well the folder "img" does exists under the public folder and inside the folder "img" , there is a folder "testsave" .
Re: change backslash to forwardslash using the public_path
Posted: Fri Oct 09, 2015 4:07 pm
by Christopher
Have you tried:
Code: Select all
$path = public_path("img\\testsave\\" . $filename);