Jump to content

How to let visitors to my website upload a zip file


jamesadrian

Recommended Posts

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:

 

<?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 image file is a actual image or fake image
if(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 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 != "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 error
if ($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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...