jamesadrian Posted February 22, 2016 Share Posted February 22, 2016 I wish to know what html form and script I must have on my website in order to allow visitors to my website to upload a zip file containing a video file. I have been given a first draft of a script that attempts to upload pictures, but it doesn't work yet: <?phpini_set('file_uploads', 'on');$target_dir = "uploads/";$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);$uploadOk = 1;$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);// Check if image file is a actual image or fake imageif(isset($_POST["submit"])) { $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]); if($check !== false) { echo "File is an image - " . $check["mime"] . "."; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; }}// Check if file already existsif (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0;}// Check file sizeif ($_FILES["fileToUpload"]["size"] > 20000000) { echo "Sorry, your file is too large."; $uploadOk = 0;}// Allow certain file formatsif($imageFileType != "mpg" && $imageFileType != "webm" && $imageFileType != "gov" && $imageFileType != "mp4" && $imageFileType != "avi"&& $imageFileType != "mov") { echo "Sorry, only video files are allowed."; $uploadOk = 0;}// Check if $uploadOk is set to 0 by an errorif ($uploadOk == 0) { echo "Sorry, your file was not uploaded.";// if everything is ok, try to upload file} else { if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; }}?> I also made a directory within the directory that contains upload.php called uploads, which seems to be consistent with the script. I would be happy if it only could upload zip files. Can anybody here suggest what I should do? Thank you for your help. Jim Adrian jim@futurebeacon.com Link to comment Share on other sites More sharing options...
jamesadrian Posted February 23, 2016 Author Share Posted February 23, 2016 I forgot to mention the form on the web page: <form action="upload.php" method="post" enctype="multipart/form-data"> Select image to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload Image" name="submit"></form> I also made the web page character set enctype: <meta http-equiv="Content-Type" content="text/html; charset=enctype" /> This all takes place on a new page here: http://www.fibro1.org/ Thank you for your help. Jim Adrian jim@futurebeacon.com Link to comment Share on other sites More sharing options...
jamesadrian Posted February 23, 2016 Author Share Posted February 23, 2016 This attempt is constructed from W3 Schools guidance. It seems strange that there are no responses. How do I ask an administrator or moderator about this? Thank you for your help. Jim Adrian jim@futurebeacon.com Link to comment Share on other sites More sharing options...
jamesadrian Posted February 23, 2016 Author Share Posted February 23, 2016 I tried a scrpt that only uploads zip files but it doesn't work either: <?php ini_set('file_uploads', 'on'); $target_dir = "uploads/"; $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION); // Check if file already exists if (file_exists($target_file)) { echo "Sorry, file already exists."; $uploadOk = 0; } // Check file size if ($_FILES["fileToUpload"]["size"] > 20000000) { echo "Sorry, your file is too large."; $uploadOk = 0; } // Allow certain file formats if($imageFileType != "zip") { echo "Sorry, only zip files are accepted."; $uploadOk = 0; } // Check if $uploadOk is set to 0 by an error if ($uploadOk == 0) { echo "Sorry, your file was not uploaded."; } else { // if everything is ok, try to upload file if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; } else { echo "Sorry, there was an error uploading your file."; } } ?> Link to comment Share on other sites More sharing options...
Ingolme Posted February 24, 2016 Share Posted February 24, 2016 What do you mean by doesn't work? Does an error message show up? Link to comment Share on other sites More sharing options...
jamesadrian Posted February 24, 2016 Author Share Posted February 24, 2016 Foxy Mod, Apparently, I must have done something wrong on my first test of this new script. It has worked properly ever since. Thank you for your reply. Jim Adrian Link to comment Share on other sites More sharing options...
jamesadrian Posted February 24, 2016 Author Share Posted February 24, 2016 (edited) How does one delete a post? Thank you for your help. Jim Adrian Edited February 25, 2016 by jamesadrian Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now