silverglade Posted December 12, 2011 Share Posted December 12, 2011 ok I got the images to upload to the directory on the server. now I got some code to try to display the image on the same page after you submit it to the directory. so it's like, submit form-> images goes in server directory->echoes back out on same page but just above the upload form. please any help greatly appreciated. thanks. here is the code so far. <?php // An Example about listing Images. $dir = "uploads/"; $odir = opendir($dir); while($file = readdir($odir)){ if(filetype($file) == "image/JPEG") { echo $file; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <p>UPLOAD YOUR PORTFOLIO AND PRICES</p> <p> </p> <p> <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form></p> </body> </html> Quote Link to comment Share on other sites More sharing options...
scootstah Posted December 12, 2011 Share Posted December 12, 2011 Wouldn't you just want to throw some <img /> tags around the echo? while($file = readdir($odir)){ if(filetype($file) == "image/JPEG") { echo '<img src="' . $file . '" />'; }/code] Quote Link to comment Share on other sites More sharing options...
silverglade Posted December 12, 2011 Author Share Posted December 12, 2011 thank you for that. I took some code from "uploader.php" and put it all in the form page , so the page should both upload it and display the image on the page reload. doesn't work though. nice idea though. LOL. please any help again appreciated. thanks. <?php // Where the file is going to be placed $target_path = "uploads/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } // An Example about listing Images. $dir = "uploads/"; $odir = opendir($dir); while($file = readdir($odir)){ if(filetype($file) == "image/JPEG") { echo '<img src="' . $file . '" />'; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <p>UPLOAD YOUR PORTFOLIO AND PRICES</p> <p> </p> <p> <form enctype="multipart/form-data" action="upload_gallery.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form></p> </body> </html> Quote Link to comment Share on other sites More sharing options...
silverglade Posted December 12, 2011 Author Share Posted December 12, 2011 I think I am making progress, here is my tiny little code, and the error message i get. Warning: filetype() [function.filetype]: Lstat failed for 0003000_1869WEB.jpg in /hermes/bosweb/web173/public_html/PHOTO/display.php on line 6 <?php // An Example about listing Images. $dir = "uploads/"; $odir = opendir($dir); while($file = readdir($odir)){ if(filetype($file) == "image/JPEG") { echo '<img src=/uploads/"' . $file . '" />'; } } ?> Quote Link to comment Share on other sites More sharing options...
silverglade Posted December 12, 2011 Author Share Posted December 12, 2011 anyone? Bueller? hehe. I changed the code to this, I get an image icon but no image on the page. please any help thanks. <?php if ($handle = opendir('uploads/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo "<img src='" . $file . "' />\n"; } } closedir($handle); } ?> Quote Link to comment Share on other sites More sharing options...
silverglade Posted December 12, 2011 Author Share Posted December 12, 2011 ok I have it narrowed down to this <?php $dir="uploads/"; if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { echo "<img src='" . $file . "' />\n"; } closedir($handle); } ?> I get 4 image blank squares icons. not the images Quote Link to comment Share on other sites More sharing options...
Drummin Posted December 12, 2011 Share Posted December 12, 2011 echo "<img src='" . $dir . $file . "' />\n"; Quote Link to comment Share on other sites More sharing options...
silverglade Posted December 12, 2011 Author Share Posted December 12, 2011 great thank you!. Also, I get a grayed out or x'ed out little image placeholder square next to the image, any more help appreciated. thanks. I have been working on this code for over an hour. LOL edit: when I added this echo "<img src='" . $dir . $file . "' width=\"75\" height=\"75\" />\n"; i get 3 blank squares and one image. Quote Link to comment Share on other sites More sharing options...
silverglade Posted December 12, 2011 Author Share Posted December 12, 2011 actually I am trying to make a thumbnail, then an image link to the larger image. like this but it isn't working <?php echo "<a href=\"http://mysite.com/\"". $dir . $file."\"><img src='" . $dir . $file . "' width=\"75\" height=\"75\" /></a>\n"; ?> Quote Link to comment Share on other sites More sharing options...
Drummin Posted December 12, 2011 Share Posted December 12, 2011 You've got an extra \" in there. echo "<a href=\"http://mysite.com/". $dir . $file."\"><img src='" . $dir . $file . "' width=\"75\" height=\"75\" /></a>\n"; Quote Link to comment Share on other sites More sharing options...
silverglade Posted December 12, 2011 Author Share Posted December 12, 2011 good eye. it feels like dissecting fleas. The page shows two blank image links, one links to the directory above uploads, and the other links to the root directory of the site. I don't know what to do please. That is about it for now, i will be happy with that. if you are able. Quote Link to comment Share on other sites More sharing options...
Drummin Posted December 12, 2011 Share Posted December 12, 2011 Wrap the echo in the if statement you have above. if ($file != "." && $file != "..") { Quote Link to comment Share on other sites More sharing options...
melloorr Posted December 12, 2011 Share Posted December 12, 2011 I have just been doing exactly what you are doing (with the same code too). And I have finally got it to work! <?php // fill an array with all items from a directory $dir = "thumbs/"; $handle = opendir($dir); while ($file = readdir($handle)) { $files[] = $file; // This removes the full stops from the array unset($files[0]); unset($files[1]); } foreach($files as $file) { echo "<img src='" . $dir . $file . "' />\n"; } ?> Quote Link to comment Share on other sites More sharing options...
silverglade Posted December 13, 2011 Author Share Posted December 13, 2011 thank you SO MUCH for that code!! it works great. what are the chances. hehe. small world. thank you. :D Quote Link to comment 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.