0

Hey my php/mysql/html people,

I have this variable that holds a path to an image and then insert it into a db (yes, I am using mysql_real_escape_string) which works perfectly.

$file_name = $_FILES["file"]["name"];
$path='images\ '. $file_name;
insert into...blah blah blah

The path is later pulled from the db and stored in said variable.

$path       = $row['file_path'];

I am trying to display it with:

 // the contents of $path in this case is: images\ cats.jpg
echo "<img src=" . $path . ">";

However the image breaks because the only thing that src pics up is: images\ and not the actualname+extension of the image. I know this probably has to do with the slashes, but I am a newbie and could use some help. Thanks in advance!

2
  • have you tried printing the variable to check if it is showing what you think it is showing? try "echo $path" before you insert into. also try "echo $path" after you retrieve it from the db. does it print what you expect it to? Commented May 1, 2013 at 3:19
  • just wondering shouldn't the path be images\cats.jpg instead of images\ cats.jpg Commented May 1, 2013 at 3:19

2 Answers 2

1

your

$path='images\ '. $file_name; 

should be

$path='images\'. $file_name;
Sign up to request clarification or add additional context in comments.

6 Comments

agreed, however as soon as i delete that space then the rest of my code in the script goes grey. This is due to the fact that the \ will actually escape the '
so just escape the \ with \\
that worked! , in terms of getting the full file path. However I am still getting broken pic icon displayed :/
try echoing $path first and see if the file is actually there
seems that the path needs to be displayed like: /images/filename.jpg
|
0

Print $path variable & see the values.

echo $path;exit;

You will get value on web browser.

Copy the value displayed on browser & paste it in the URL, if you see the image, your saved path is correct, if not, you have gone wrong in specifying the relative path too the resource.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.