KaiSheng Posted January 16, 2014 Share Posted January 16, 2014 Firstly, i wanna say that all my codes were working perfectly fine in a localhost. After that, transfers to a domain, putting the website online. My codes do not function properly after that. What i want to achieve is to display the images i have uploaded into the database, from the folder called image. I'll show code. This is the page where the process of uploading takes place. if ((($_FILES["picture"]["type"] == "image/gif") || ($_FILES["picture"]["type"] == "image/jpeg") || ($_FILES["picture"]["type"] == "image/jpg") || ($_FILES["picture"]["type"] == "image/pjpeg") || ($_FILES["picture"]["type"] == "image/x-png") || ($_FILES["picture"]["type"] == "image/png")) ) { if ($_FILES["picture"]["error"] > 0) { echo "Return Code: " . $_FILES["picture"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["picture"]["name"] . "<br />"; echo "Type: " . $_FILES["picture"]["type"] . "<br />"; echo "Size: " . ($_FILES["picture"]["size"]) . " Kb<br />"; echo "Temp file: " . $_FILES["picture"]["tmp_name"] . "<br />"; if (file_exists("image/" . $_FILES["picture"]["name"])) { echo $_FILES["picture"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["picture"]["tmp_name"], "image/" . $_FILES["picture"]["name"]); echo "Stored in: " . "../image/" . $_FILES["picture"]["name"]; } } } else { echo "Invalid file"; } --- This is the viewing of the displayed images. while ($row = mysqli_fetch_array($result)) { $id = $row['id']; $username = $row['username']; $category = $row ['category']; $description = $row['description']; $date_found = $row['date_found']; $picture = $row['picture']; $image = "<img src='image/$picture' />"; $date_submitted = $row['date_submitted']; $outlet = $row['outlet']; $item_match = $row['item_match']; ?> <tr> <td><?php echo $category; ?></td> <td><?php echo $description; ?></td> <td><?php echo $date_found; ?></td> <td><img src=""<?php echo $picture;?> height="100" width="100"</td> <td><?php echo $date_submitted; ?></td> <td><?php echo $outlet; ?></td> <td><?php echo $username; ?></td> <td><?php echo $item_match; ?></td> It is not working for the display area. Can someone help? thanks. Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/ Share on other sites More sharing options...
Barand Posted January 16, 2014 Share Posted January 16, 2014 It is not working for the display area. The tells us nothing. It what way is "not working". Do you get any results displayed? Do you get any errors? Do you have error_reporting turned on? Do you get an error from mysqli_error? Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/#findComment-1465392 Share on other sites More sharing options...
KaiSheng Posted January 17, 2014 Author Share Posted January 17, 2014 Not working refers to no image displayed. There are no errors shown. I think it's something related to the echo of the image line, however i searched and tried all kinds of <img src code, it doesn't work. (Or maybe the path.. but i have no idea how to change it.) I have a folder called LN, inside LN is all my codes, inside LN also contains the folder called image. I want to display the picture inside the folder called image. Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/#findComment-1465513 Share on other sites More sharing options...
KaiSheng Posted January 17, 2014 Author Share Posted January 17, 2014 Anyone knows how? Display image from the image folder. It is a different folder with the php file. Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/#findComment-1465546 Share on other sites More sharing options...
cyberRobot Posted January 17, 2014 Share Posted January 17, 2014 The echo statement needs to be inside the quotes here: <td><img src="<?php echo $picture;?>" height="100" width="100"></td> Also note that I added the end ">" for the image tag. Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/#findComment-1465557 Share on other sites More sharing options...
KaiSheng Posted January 20, 2014 Author Share Posted January 20, 2014 Awww... It's not working. Because the path is inside a folder called image. The code you shown me is echo-ing picture from the current folder same as the php file. ): Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/#findComment-1465822 Share on other sites More sharing options...
Barand Posted January 20, 2014 Share Posted January 20, 2014 have you tried $picture = $row['picture']; $image = "<img src='image/$picture' height='100' width='100' />"; followed by <td><?php echo $image;?></td> Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/#findComment-1465842 Share on other sites More sharing options...
KaiSheng Posted January 22, 2014 Author Share Posted January 22, 2014 (edited) No. it didn't show any. Edited January 22, 2014 by KaiSheng Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/#findComment-1466102 Share on other sites More sharing options...
cyberRobot Posted January 22, 2014 Share Posted January 22, 2014 Perhaps the image tag isn't pointing to the right folder. Have you tried using root-relative links? $image = "<img src='/image/$picture' height='100' width='100' />"; Note that I added the slash before the "image" folder. Of course, your image folder may not be in the root director. You'll need to modify the path to match where the images are being uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/285400-how-to-display-image-from-database/#findComment-1466147 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.