Upload ZIP file using a form

Category: How To

mikecam3
Asked:
2013-06-24 12:26 pm EST

Hits: 2,068

I am trying to upload a ZIP file using a HTML form with PHP doing the work. I have had success with other file types, but ZIP does not want to upload.

I have added MIME types though the server panel, with no luck to help my problem.

Please advice next course of action.

User: ctarfq5
PHP Code:

for($i=0;$i<10;$i++)
{
$target_path = "CTA/";

$target_path = $target_path . basename( $_FILES['ULfile']['name'][$i]);

if ($target_path != "CTA/")
{
echo $target_path;
echo "<br />";
}

echo $_FILES['ULfile']['tmp_name'][$i];
echo "<br />";

$fh=fopen('Upload Errors.txt','a');
fwrite($fh, 'Failed to Upload: ');
fclose($fh);

if ($target_path != "CTA/")
{
if(move_uploaded_file($_FILES['ULfile']['tmp_name'][$i], $target_path))
{
echo "The file ". basename( $_FILES['ULfile']['name'][$i])." has been uploaded";
echo "<br />";
}
else
{
$fh=fopen('Upload Errors.txt','a');
$tStr="\n\r". basename( $_FILES['ULfile']['name'][$i]);
fwrite($fh, $tStr);
fclose($fh);
}
}
}

Thanks.

You must login before you can ask a follow up question.

You must login before you can submit an answer.

OTHER ANSWERS

0

jamesr
Staff
5,889 Points
2013-06-24 12:33 pm EST
Hello mikecam3!

What is the Form part of the code so we can test the upload? We can test it to see whats wrong. Please respond back with the full code you are using.

Best regards,
James R

You must login before you can post a comment about this answer.

<html>
<head>
<title>Sales RFP Builder</title>

<meta http-equiv="Content-Type" content="application/vnd.wap.xhtml+xml; charset=UTF-8">

<meta name="Handheld Friendly" content="True">
<meta name="Mobileoptimized" content="320">
<meta name="viewport" content="width=device-width">


<link rel="stylesheet" href="CTA.css" type="text/css" charset="utf-8">

<style>
h6
{
margin-top: -1.5em;
}
img
{
margin-bottom: -0.375em;
}


</style>

<SCRIPT LANGUAGE="JavaScript">

</SCRIPT>

</head>

<body>
<div align="center">

<image src="cta.jpg" width="300" height="93" alt="CTA Logo" />

<h1>Email Attachments</h1>
</div>

<!--<form enctype="multipart/form-data" action="http://127.0.0.1/projects/ctarfq/EmAtt2.php" method="POST">-->

<form enctype="multipart/form-data" action="EmAtt2.php" method="POST">

<p>User:<br />
<input type="text" name="User_Name"></p>

<input type="hidden" name="MAX_FILE_SIZE" value="1024000" />
Choose a file to upload: <br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input name="ULfile[]" type="file" /><br />
<input type="submit" value="Upload Files" />
</form>


</body>
</html>
mikecam3
38 Points
2013-06-24 12:53 pm EST
Thank you for the full code. I placed the full code into one file called test.php in your public_html. I was able to get the form working as is. I uploaded bootstrap.zip through it and it went to the CTA folder. What error do you get?
jamesr
5,889 Points
Staff
2013-06-24 2:34 pm EST
I am not getting a PHP error, it would not upload and send the file out. I tried another zip file I had and it worked. I just hope it was a weird case. The key to this whole thing has really been MIME types and declare them correctly. Thank you for your help.
mikecam3
38 Points
2013-06-24 4:23 pm EST
Like this Question?

Related Articles

It looks like there are no related articles.
Would you like to ask a question about this page? If so, click the button below!
Ask a Question

Need more Help?

Search

Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail: support@InMotionHosting.com
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!