steve490 Posted February 5, 2010 Share Posted February 5, 2010 Hey, Im trying to make pictures display from the server but all im getting back is a broken picture, the folder is on 755 and i've tried 777 but neither work. Also I can right click on the broken image, click on view image and I can view it in the 'index of uploads' here's the code for the query and how im calling it. $conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '****'; mysql_select_db($dbname); $image_viewer = "SELECT * FROM table WHERE email='$_SESSION[email]'"; $show_image = mysql_query($image_viewer); im then calling it in my HTML while($info = mysql_fetch_array( $show_image )) { echo "<img src=/uploads".$info['uploadedfile'] ."> <br>"; echo "<b>Name:</b> ".$info['name'] . "<br> "; } Cheers Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/ Share on other sites More sharing options...
taquitosensei Posted February 5, 2010 Share Posted February 5, 2010 If that's a relative path get rid of the / at the beginning Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1007527 Share on other sites More sharing options...
steve490 Posted February 5, 2010 Author Share Posted February 5, 2010 Thanks for the reply, Unfortunately it didn't do the trick (although the slash needed to be removed), still the same things happening Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1007533 Share on other sites More sharing options...
taquitosensei Posted February 5, 2010 Share Posted February 5, 2010 right click on the broken image and copy the location the paste that into a browser window. Just to make sure the path is correct and the filename is correct. Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1007541 Share on other sites More sharing options...
steve490 Posted February 5, 2010 Author Share Posted February 5, 2010 Ye it took me to the file directory and listed the images, which I can click on and then it displays the images:- Index of /uploads * Parent Directory * img1.jpg * img2.jpg Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1007542 Share on other sites More sharing options...
litebearer Posted February 5, 2010 Share Posted February 5, 2010 if "uploads" is a folder, then you need the slash "/" between it and the file name Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1007545 Share on other sites More sharing options...
steve490 Posted February 5, 2010 Author Share Posted February 5, 2010 didn't work but... Im trying to display the images in 'profile.php' page so could the problem be in this area? Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1007550 Share on other sites More sharing options...
PFMaBiSmAd Posted February 5, 2010 Share Posted February 5, 2010 Ye it took me to the file directory and listed the images That's not what you were asked to check as the result of doing that. You were asked to check if the path and the filename is correct. Based on the results, there is no filename present and that would either indicate that $info['uploadedfile'] contains nothing or it does not exist because the column is actually named something else. Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1007554 Share on other sites More sharing options...
steve490 Posted February 8, 2010 Author Share Posted February 8, 2010 Ok that was the problem thank you Although the pictures are displaying now, its the same picture, so img2 will display the same image as img1 (the last upload changes all other pictures to the latest one but the file names stay the same). heres my upload and the method im using to call the pictures from the database and server:- $conn2 = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = '****'; mysql_select_db($dbname); { $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $pic = ($_FILES['uploadedfile']['name']); mysql_query ("INSERT INTO img (name, email) VALUES ('uploads/$pic','$_SESSION[email]')"); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded to" . $target_path; } else{ echo "There was an error uploading the file, please try again!"; } $image_viewer = "SELECT * FROM img WHERE email='$_SESSION[email]'"; $show_image = mysql_query($image_viewer); mysql_close($conn2) This is where im calling the pictures from the server and database while($info = mysql_fetch_array( $show_image )) { //Outputs the images echo "<img src=/uploads/$pic".$info['uploadedfile'] ."> <br>"; echo "<b>Name:</b> ".$info['name'] . "<br> "; } Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1008846 Share on other sites More sharing options...
taquitosensei Posted February 8, 2010 Share Posted February 8, 2010 Start a new topic. Quote Link to comment https://forums.phpfreaks.com/topic/191074-broken-image-when-displaying-an-uploaded-picture/#findComment-1008851 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.