Sonu's avatar
Level 3

Image Path Stores With Forward(\) Slash In Db Why ? Help Heeded

When I Upload An Image Its Path Stores With Forward () Slash In Db Don't Know Why This Happenz

Here Is Code
$image = Request::file('image');
$destinationPath = 'uploads/';
$name = time().'-'.$image->getClientOriginalName();
$path = Request::file('image')->move($destinationPath, $name);
$user->image_path = $path;
$user->save();

Image Path Saves In Db But In Wrong Way Like This uploads\1428506792-Hydrangeas.jpg

But why Its Inserted With Forward Slash ? I Need This Path uploads/1428506792-Hydrangeas.jpg

0 likes
6 replies
davorminchorov's avatar
$image = Request::file('image'); 
$destinationPath = 'uploads/'; 
$name = time().'-'.$image->getClientOriginalName(); 
$path = Request::file('image')->move($destinationPath, $name); 
$user->image_path = $path; 
$user->save();

Formatted your code so it's easier to read.

1 like
Sonu's avatar
Level 3

Hey Ruffles How can i Formatted My Code Here. I Am New Here

Dave_Martin's avatar

Why worry about the direction of the slash? If you are going to end up using it in a src= tag in HTML you will want it to have that forward slash. PHP itself does not much care.

davorminchorov's avatar
 put the code between 3 ` like:
// ```
// code here
// ```
more info at the link near the "Post your Reply" button
1 like
SachinAgarwal's avatar
Level 21

@sonu its better you just save the name of the file to the database and its obvious you will know the directory path as you are writign logic so fetch only name of the file and eco out the filepath yourself.

1 like
Sonu's avatar
Level 3

Thanks SachinAgarwal And Ruffles

I am now using str_replace to change forward slash to back and its works now.

Please or to participate in this conversation.