-1

i am trying to upload a zip file with php. but it is not uploaded to temporary folder..when i am printing the $_FILES array in the posted action , values of fields type,tmp_name becomes null and error field becomes 1 .which means file not uploaded to temporary folder... but uploading of image files becomes success..this issue is only in the case of zip files..can anyone help me please.

here is the code

encrypt-zip-file.phtml

<form action="<?php echo $this->basePath() ?>/encrypt-zip-file" method="post"enctype="multipart/form-data">
Select zip file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload" name="submit">
</form>

code in the action

        $target_dir  = $_SERVER['DOCUMENT_ROOT']."/zip_files/";
        $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
        $uploadOk = 1;
        move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
sahira shamsu
  • 47
  • 2
  • 11

2 Answers2

2

Php does not restrict file upload types. All the file types are supported.

But there are certain configuration related to uploads like file_upload, max_file_uploads, upload_max_filesize

It could be possible that the zip file is going beyond the allowed limit.

http://en.wikipedia.org/wiki/Internet_media_type

Bhavya Shaktawat
  • 2,504
  • 1
  • 13
  • 11
  • configurations in php.ini file is file_uploads=On,upload_max_filesize=2M,max_file_uploads=20 – sahira shamsu Nov 22 '14 at 08:28
  • Your `upload_max_filesize=2M` is less than your file size, which is only reason you can not upload that .zip file. Increase `upload_max_filesize` and check again. [this](http://stackoverflow.com/questions/2184513/php-change-the-maximum-upload-file-size) SO thread will help you to increase memory limit. – Domain Nov 22 '14 at 08:31
  • increase upload_max_filesize since your zip files is beyond 2M – Bhavya Shaktawat Nov 22 '14 at 08:34
1

There might be any problem in page in which you might be encrypting that zip

the code i have tried works like charm and it is as below

<?php
if($_POST){
$target_dir  = $_SERVER['DOCUMENT_ROOT'];
        $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
        $uploadOk = 1;
        move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
}
?>
<form action="index.php" method="post"enctype="multipart/form-data">
Select zip file to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload" name="submit">
</form>

if it still doesn't work then check configuration parameters such as file_upload, max_file_uploads, upload_max_filesize in php.ini file

Nikunj Sardhara
  • 638
  • 1
  • 5
  • 20