andy_b_1502 Posted January 18, 2012 Share Posted January 18, 2012 Hi everyone!! I have looked into how the upload script works and this is what i have: <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { 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"]; } } } else { echo "Invalid file"; } ?> Which is un-tested at the moment, but let's just say for talking sake it worked 100% what elements of this script would i be looking at to display the files uploaded on to another page, in my case my homepage? ive found as to yet, that the uploads have to be stored on a file somewhere on my server, which i've set up. But i thought it would be just as easy to have a field in my table named upload and display it within the table next to the other results? instead i just get whatever the file name is named.jpg. Any help in looking towards the answer? many thanks in advance guys! Quote Link to comment https://forums.phpfreaks.com/topic/255288-display-uploaded-images/ Share on other sites More sharing options...
Muddy_Funster Posted January 18, 2012 Share Posted January 18, 2012 how are you storing and retrieving the information from the table? Quote Link to comment https://forums.phpfreaks.com/topic/255288-display-uploaded-images/#findComment-1308890 Share on other sites More sharing options...
jotorres1 Posted January 18, 2012 Share Posted January 18, 2012 Not quite sure what you are getting at, but you would need this: <?php $file_path = "upload/" . $_FILES["file"]["name"]; ?> If you have a table of uploads or whatever you want to call it, be sure to have a field for this path. For example, having image_path as a column in your table. Then, you would have to save $file_path into that field. When displaying this same image, all you would need is something like this: assuming you already worked your mysql etc... <?php echo '<img src="'.$row['image_path'].'" />'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/255288-display-uploaded-images/#findComment-1308895 Share on other sites More sharing options...
Drongo_III Posted January 18, 2012 Share Posted January 18, 2012 Also worth familiarising yourself with this mate - http://uk3.php.net/manual/en/features.file-upload.php . Get to know the $_files array - it'll help you a lot cos i know i found it all a bit confusing at first. Hi everyone!! I have looked into how the upload script works and this is what i have: <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { 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"]; } } } else { echo "Invalid file"; } ?> Which is un-tested at the moment, but let's just say for talking sake it worked 100% what elements of this script would i be looking at to display the files uploaded on to another page, in my case my homepage? ive found as to yet, that the uploads have to be stored on a file somewhere on my server, which i've set up. But i thought it would be just as easy to have a field in my table named upload and display it within the table next to the other results? instead i just get whatever the file name is named.jpg. Any help in looking towards the answer? many thanks in advance guys! Quote Link to comment https://forums.phpfreaks.com/topic/255288-display-uploaded-images/#findComment-1308912 Share on other sites More sharing options...
andy_b_1502 Posted January 19, 2012 Author Share Posted January 19, 2012 Okay, getting in a bit of a mess here trying different things out. <form method="post" action="basicpackage-send.php"> Compnay Name:<br /><br /> <input type="text" name="company_name" id="compnay_name" size="30" /><br /><br /> Six Bullet Point Description:<br /><br /> <textarea name="basicpackage_description" id="basicpackage_description" rows="7" cols="21">. . . . . . </textarea><br /><br /> Location:<br /><br /> <input type="text" name="location" id="location" size="50" /><br /><br /> Postcode:<br /><br /> <input type="text" name="postcode" id="postcode" size="15" /> <br /> <form method="post" action="uploads folder on server (path)" enctype="multipart/form-data"> Please specify a file, or a set of files:<br /> <br /> <input type="submit" name="browse" value="browse" /> <input type="text" name="browse" id="browse" size="20" /> <br /> <br /> <input type="submit" name="Submit" value="upload" /> </form> <input type="submit" name="Submit" value="go" /> </form> I know this is incorrect particularly the "browse" button, then the upload. Do i send the image straight to the server some way here? OR do i use an additional php script to send it off? either way i need to have the image sent WITH all the other information in the form to the database, then have that info displayed- i'll figure out that at a later date. Can i send all the data in one? images with all other fields? just thought i'd take a minute out and ask you lot before i further confuse myself. Thank you for your help so far Quote Link to comment https://forums.phpfreaks.com/topic/255288-display-uploaded-images/#findComment-1309229 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.