Display last uploaded image

I want to display the last uploaded image from a database. My code displays the name of the file but not the image itself. Can someone help me what is wrong with my code. Here’s the code:

<?php ini_set("memory_limit","128M"); ini_set("post_max_size","64M"); ini_set("upload_max-filesize","64M"); if(isset($_POST['ok'])) { if($_FILES['fajl']['name']!="") { if($_FILES['fajl']['type']!=="image/jpeg") { if($_FILES['fajl']['error']==0) { if(!is_dir("uploads")) { mkdir("uploads"); } $filename=basename($_FILES['fajl']['name']); move_uploaded_file($_FILES['fajl']['tmp_name'],"uploads/".$filename); $location="uploads/".$filename; if(file_exists("uploads/".$filename)) { $error="Sikeres fájlfeltöltés!"; $con = mysql_connect("localhost","root",""); if (!$con) { die ("Kapcsolódás nem sikerült a kapcsolódás ehhez: " . mysql_error()); } mysql_select_db("image_uploader",$con); $sql = mysql_query("INSERT INTO data (id,location) VALUES ('','$location')"); //$last=printf("Utoljára feltöltött kép ID-ja: %d\n", mysql_insert_id()); } else { $error="A Fájl feltöltése sikertelen!"; } } else { $error="Hiba a feltöltés során: ".$_FILES['fajl']['error']; } } else { $error="Hibás fájlformátum - csak JPEG megengedett"; } } else { $error="Nem adott meg fájlt!"; } } if(isset($error)) { print($error); } echo "
"; echo ("Legutoljára feltöltött fájl:"); echo "
"; $con = mysql_connect("localhost","root",""); if (!$con) { die ("Nem sikerült kapcsolódni a következő adatbázishoz:" . mysql_error()); } else { mysql_select_db("image_uploader",$con); $record=("SELECT location FROM data WHERE id=(SELECT max(id) FROM data)") or die ("Kiválasztás nem sikerült"); $myData = mysql_query ($record); } while($record = mysql_fetch_array($myData)) { $lastimage=$record['location']; echo $lastimage; echo "
"; } ?> utolso kep
Kérem töltsön fel egy JPEG fájlt.(Max 2MB)

you are using mysql_fetch_array (which fetches an ordinary array) to fetch an associative array. Try replacing mysql_fetch_array with mysql_fetch_assoc

Unfortunately it didn’t help. Any other idea?

Your tag is nor formatted correctly

[php]utolso kep
[/php]

try that…

Unfortunately it doesn’t work :frowning:

I modified the line to this:

utolso kep

but still cannot see the image

View the Source and look at the IMG line to see what is being entered from the $lastimage variable

Finally it works. Thank so much for your help. :slight_smile:

It was the space after the uploads/ wasn’t it?

No, uploads was also included in $lastimage and also written after img.

So the path was uploads/uploads.

That was the error
Thanx again for you big help :slight_smile:

Not a problem! :smiley:

You should mark this completed/answered.

How can I do that? I’m new here…

See if you can change the message icon to solved as the originator of the topic.

There should be a button at the bottom of the page that says topic solved.

OK, i’ve found it. Thanx.

Sponsor our Newsletter | Privacy Policy | Terms of Service