user1327746
user1327746

Reputation: 37

PHP File upload (Images)

Just a quick questions guys. I'm using a 'browse' upload function within a form to select and upload a picture to my database. At the moment my images are in a 'Image' folder and to get them to show I need the following within my Image column:

Images\picname1.jpg

When I use the browse upload function, I get the following:

E:\xampp\htdocs\IDB\images\picname1.jpg

which is the displayed on the database as:

picname1.jpg

And of course as the 'Image' folder directory isn't included, the image will not display.

This is my form:

<font face="Arial"><b>Enter Image(Optional):</b></font><input type="file" name="imaAdd"   accept="image/gif">

Could anyone tell me how I can include the 'Image directory!? I'm sure its an obvious fix I'm missing!

Any help would be great!

Edit:

Hers my Image echo guys.

    echo"<img src='".$row->Image."'>";

Upvotes: 0

Views: 147

Answers (2)

kjones
kjones

Reputation: 1423

One option would be to concatenate the string 'images/' with the image filename upon insertion into your database.

A better option would probably be to qualify the filename with the images path when you go to display the image. If you can show us the code you use to display the images, it should be an easy fix.

The PHP code for this latter option could look like:

echo '<img src="images\' . $imagename . '" />';

Upvotes: 2

SpeedCrazy
SpeedCrazy

Reputation: 517

I'm slightly confused by what you are asking, correct me if im wrong but this is what you have:

An upload system that uploads pictures to your image directory and adds imageName.jpg to your database. And you want to prefix 'images\' to each of the image names added to your database?

If thats the case, in your php script that the form triggers you should be able to set the image name as added to the db as 'image\.$imagename' assuming $imagename as the name of the image.

And if that does not work why not prefix it while accessing the img? print '<img src=image\"'.$imagename.'" /> Hope that helps.

Upvotes: 0

Related Questions