jcbones Posted September 6, 2011 Share Posted September 6, 2011 The header() function cannot be used after output has been sent to browser. This includes any HTML outside of PHP, and whitespace outside of PHP, or any echo, print, print_r, etc. (any function or construct that outputs to the page, including errors, notices, etc.). Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266181 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 The header() function cannot be used after output has been sent to browser. This includes any HTML outside of PHP, and whitespace outside of PHP, or any echo, print, print_r, etc. (any function or construct that outputs to the page, including errors, notices, etc.). header("Location:display.php?imageName=".$file_name ); exit(); So this line is not needed? However, why is the display.php not showing up? I am not following that. So, if I get rid of that header, what route do I use to get location? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266197 Share on other sites More sharing options...
AmericanAlien Posted September 6, 2011 Author Share Posted September 6, 2011 The header() function cannot be used after output has been sent to browser. This includes any HTML outside of PHP, and whitespace outside of PHP, or any echo, print, print_r, etc. (any function or construct that outputs to the page, including errors, notices, etc.). Ok, from what I am reading, I do need the header, unless I am interpreting it incorrectly. How would I achieve this type of result? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266229 Share on other sites More sharing options...
radiations3 Posted September 7, 2011 Share Posted September 7, 2011 Following code is the path of image into the variable and simply displaying the image from that path. If you know the path where the image is being saved temporarily on your server then you can easily display it by using the following code but make sure your image is getting saved first.. <img src = "<?php echo $pic; ?>" width="100" height="100" /> Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266287 Share on other sites More sharing options...
AmericanAlien Posted September 7, 2011 Author Share Posted September 7, 2011 Following code is the path of image into the variable and simply displaying the image from that path. If you know the path where the image is being saved temporarily on your server then you can easily display it by using the following code but make sure your image is getting saved first.. <img src = "<?php echo $pic; ?>" width="100" height="100" /> Thanks for the help! I had to go in another direction for now. A quick question, how is that code displaying the pic in a new page? I see it sources the pic, but I do not see how it takes the pic and places it into an html or even php page in a type of gallery. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266592 Share on other sites More sharing options...
radiations3 Posted September 8, 2011 Share Posted September 8, 2011 FINAL WORKING CODE EXAMPLE OF UPLOADING IMAGES AND DISPLAYING THEM BY PUTTING SOME REQUIRED RESTRICTIONS ON THE UPLOADED FILE: NOTE: BEFORE USING MY CODE CREATE ThE FOLDER named as 'upload' from where you are running my code. Upload form.php <html> <body> <form action="upload-restrict.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> upload-restrict.php <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg")) && ($_FILES["file"]["size"] < 2000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; // echo '<img src = . "upload/" . $_FILES["file"]["name"] />'; echo "<br />"; echo "<br />"; echo "<img src='upload/" . $_FILES["file"]["name"]. "'>" ; // File is getting displayed from here } } } else { if (($_FILES["file"]["type"] != "image/jpeg")) echo "Invalid file TYPE"; if (($_FILES["file"]["size"] < 20000)) echo "\nInvalid file size"; else { echo "Invalid file unknwon reason"; } } ?> The answer of your question if you mean the sources "PATH of the image like upload/picname.jpeg" All you need to do is assign that path to $pic and <img src = "<?php echo $pic; ?>" width="100" height="100" /> will display the image on the page. NOTE: BEFORE USING MY CODE CREATE ThE FOLDER named as 'upload' from where you are running my code. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266661 Share on other sites More sharing options...
AmericanAlien Posted September 8, 2011 Author Share Posted September 8, 2011 FINAL WORKING CODE EXAMPLE OF UPLOADING IMAGES AND DISPLAYING THEM BY PUTTING SOME REQUIRED RESTRICTIONS ON THE UPLOADED FILE: NOTE: BEFORE USING MY CODE CREATE ThE FOLDER named as 'upload' from where you are running my code. Upload form.php <html> <body> <form action="upload-restrict.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> </body> </html> upload-restrict.php <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg")) && ($_FILES["file"]["size"] < 2000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; // echo '<img src = . "upload/" . $_FILES["file"]["name"] />'; echo "<br />"; echo "<br />"; echo "<img src='upload/" . $_FILES["file"]["name"]. "'>" ; // File is getting displayed from here } } } else { if (($_FILES["file"]["type"] != "image/jpeg")) echo "Invalid file TYPE"; if (($_FILES["file"]["size"] < 20000)) echo "\nInvalid file size"; else { echo "Invalid file unknwon reason"; } } ?> The answer of your question if you mean the sources "PATH of the image like upload/picname.jpeg" All you need to do is assign that path to $pic and <img src = "<?php echo $pic; ?>" width="100" height="100" /> will display the image on the page. NOTE: BEFORE USING MY CODE CREATE ThE FOLDER named as 'upload' from where you are running my code. The code is working AWESOMELY! The actually shows up this time. I appreciate your hard work. One thing. This is a permanent page, the pics do not stay in that page so others can view it. Is this not possible? What I mean is, is there a way to have each picture that is upload to stay on the webpage in the order uploaded and others can view this page as well? Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266689 Share on other sites More sharing options...
radiations3 Posted September 8, 2011 Share Posted September 8, 2011 Well it is possible. I am just giving you a suggestion If you would like to display images to a gallery that are being uploaded then all you have to do is to use loops in order to display all the images from certain directory into the gallery dynamically but this thing can very very very easily done if you use databases . For more help i recommend you to watch video tutorial step by step coding for adding and displaying an image from certain directory http://www.youtube.com/watch?v=dHq1MNnhSzU&feature=youtube_gdata A complete tutorial step by step of how to make an Image Upload Website, MANAGE GALLERY ETC http://www.youtube.com/watch?v=geoF9fqQbKI&feature=youtube_gdata I hope your issue will gonna resolve. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266887 Share on other sites More sharing options...
AmericanAlien Posted September 8, 2011 Author Share Posted September 8, 2011 Well it is possible. I am just giving you a suggestion If you would like to display images to a gallery that are being uploaded then all you have to do is to use loops in order to display all the images from certain directory into the gallery dynamically but this thing can very very very easily done if you use databases . For more help i recommend you to watch video tutorial step by step coding for adding and displaying an image from certain directory http://www.youtube.com/watch?v=dHq1MNnhSzU&feature=youtube_gdata A complete tutorial step by step of how to make an Image Upload Website, MANAGE GALLERY ETC http://www.youtube.com/watch?v=geoF9fqQbKI&feature=youtube_gdata I hope your issue will gonna resolve. Trust me, you have helped me a ton. I understand the loop route you speak of. I have tried that from the start, but maybe my paths are not inputted correctly. Maybe I can do what I do with my forms and have the info (pics)inputted into a form type php document. I think that may work, I have not tried that yet. Your code was the first code that actually worked, and I think I can use that and use my form method and integrate them or mesh them together. At least I hope so. Again, thanks for your tremendous help, absolutely appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266974 Share on other sites More sharing options...
radiations3 Posted September 8, 2011 Share Posted September 8, 2011 The links may help you alot and get you to the point what you seek for... If your issue is being solved kindly mark it as solved.. Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1266988 Share on other sites More sharing options...
kaore Posted February 23, 2013 Share Posted February 23, 2013 Have you tried using an iframe? I was looking for a way to do this and eventually wrote up this article: [color=rgba(0, 0, 0, 0.]http://tech.cibul.net/upload-and-display-an-image-without-a-page-refresh/[/color] Quote Link to comment https://forums.phpfreaks.com/topic/246514-display-images-after-image-upload/page/2/#findComment-1414427 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.