change backslash to forwardslash using the public_path

Discussion for various published PHP frameworks, including Zend Framework, CodeIgniter, Kohana, CakePHP, Yii, Symfony, and others.

Moderator: General Moderators

Post Reply
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

change backslash to forwardslash using the public_path

Post by gautamz07 »

I am using the IMAGINEhttps://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 ?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: change backslash to forwardslash using the public_path

Post by Christopher »

I think you should use only forward slashes. PHP makes them work on windows. If you mix them it gets confused.
(#10850)
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: change backslash to forwardslash using the public_path

Post 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
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: change backslash to forwardslash using the public_path

Post by gautamz07 »

i know that windows does't really bother weather its a forward or a backslash.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: change backslash to forwardslash using the public_path

Post by Celauran »

What's the other code surrounding that? Have you check that the file does in fact exist?
User avatar
gautamz07
Forum Contributor
Posts: 331
Joined: Wed May 14, 2014 12:18 pm

Re: change backslash to forwardslash using the public_path

Post 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" .
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: change backslash to forwardslash using the public_path

Post by Christopher »

Have you tried:

Code: Select all

             $path = public_path("img\\testsave\\" . $filename);
(#10850)
Post Reply