AlenD Posted May 30, 2011 Share Posted May 30, 2011 I'm beginning with simple codes to understand how things work and work my way up with what I need. My upload form looks like this: <form name="upload about" action="display.php" enctype="multipart/form-data" method="post"> Header: <input type="text" name="header" /> Body: <input type="text" name="body" /> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> Image: <input type="file" name="pic" /> <input type="submit" /> </form> And my display page is just as simple. <?php echo $_POST["header"]; ?> <?php echo $_POST["body"]; ?> <?php echo $_FILES['pic']['name']; ?> The problem is, whenever I submit the data, everything is fine, except the image does not display and just posts the filename of the image I uploaded. According to my research setting the enctype to multipart/formdata should display the image, but it does not. Can anyone tell me what's wrong? Quote Link to comment https://forums.phpfreaks.com/topic/237891-displaying-an-uploaded-image-using-a-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 30, 2011 Share Posted May 30, 2011 I recommend that you read the upload section of the php.net documentation - http://us2.php.net/manual/en/features.file-upload.php Quote Link to comment https://forums.phpfreaks.com/topic/237891-displaying-an-uploaded-image-using-a-form/#findComment-1222432 Share on other sites More sharing options...
AlenD Posted May 30, 2011 Author Share Posted May 30, 2011 Hello sir, I have been reading that documentation, as you can see the example I have given uses the same example given in the POST method page. It has been said that the important things are that the file size shouldn't exceed the limit, and I have to set the form enctype, in which I have put attention to both. Can you please tell me what is wrong so I may pinpoint my mistake and learn from it? Quote Link to comment https://forums.phpfreaks.com/topic/237891-displaying-an-uploaded-image-using-a-form/#findComment-1222452 Share on other sites More sharing options...
mikesta707 Posted May 30, 2011 Share Posted May 30, 2011 Your code is working as intended. You ask PHP to display (among other things) the name of the uploaded file with this line <?php echo $_FILES['pic']['name']; ?> if you wanted your browser to render an image, you would need to tell it to do so with an img tag. There are a few steps that you must take before you can do this though (like moving the file from the temporary directory where all uploaded images are stored). I suggest you continue reading the manual entry, and a few other file uploading tutorials if needed. Quote Link to comment https://forums.phpfreaks.com/topic/237891-displaying-an-uploaded-image-using-a-form/#findComment-1222453 Share on other sites More sharing options...
AlenD Posted May 31, 2011 Author Share Posted May 31, 2011 Thank you sir for directing me to the right path, I have successfully transfered the temporary folder to a designated folder in the web tree, then display it with image tags. But my current problem is the image path has a fixed name, and if I upload a different file with a different file name, the image will not be displayed because indeed the file name is different. What is the way to make the file for the image tag dynamic? Quote Link to comment https://forums.phpfreaks.com/topic/237891-displaying-an-uploaded-image-using-a-form/#findComment-1222719 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.