| 1. |
Solve : HTML file upload, size limit? |
|
Answer» Hey, thanks Kpac, and all this PHP code goes in the html file or a seperate php? No it doesn't, it all goes in one single PHP or PHTML file... Quote from: macdad- on February 08, 2009, 03:51:49 PM thanks Kpac, and all this PHP code goes in the html file or a seperate php? Well, you could use your normal HTML page to display the form, and put an action ATTRIBUTE in the form tag: <form action="upload.php">...</form>so then i would put the could in a seperate php file with "action='upload.php'"? Actually, the above example with only temporarily store the images, unless the tell it to store them. This is the HTML file with the form to upload the file: Code: [Select]<html> <body> <form action="upload.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> And this is the PHP file, called upload.php, that actually uploads the file and stores in a folder. Code: [Select]<?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"; } ?> Does that explain it well enough? yup, Thanks Kpac No problem. |
|