views:

1149

answers:

2

Hey!

I am using the following code to upload and extract a ZIP-archive in PHP using CodeIgniter.

    $config['upload_path'] = 'backups/';
 $config['allowed_types'] = 'zip';
 $config['file_name'] = $project_id;

 $this->load->library('upload', $config);

 if ( file_exists('backups/' . $project_id . '.zip') ) {
  try {
   delete_file('backups/' . $project_id . '.zip');
  } catch (exception $e) {
   // do nothing...
  }
 }

 if ( $this->upload->do_upload('zip_archive') ) {
  $upload_data = $this->upload->data();

  $file_name = 'backups/'.$upload_data['file_name'];

  $this->sync_model->extract_zip_archive($project_id, $file_name, TRUE);

  echo "Success";
 } else {
  echo $this->upload->display_errors('<p>','</p>');
 }

I get the error though "The filetype you are attempting to upload is not allowed." even though it is a valid .zip file I am uploading. (It's size does not exceed the maximum allowed)

This problem also occurs with every filetype I've tried that's not an image.

Any pointers? Cheers!

+3  A: 
$config['allowed_type']

Should be a list of mime types, but it just so happens that sometimes just the file extension will work (this is the case with images at least).

Try:

$config['allowed_type'] = 'application/zip';

Although these are also mime types for zip:

application/x-zip
application/x-zip-compressed
application/octet-stream
application/x-compress
application/x-compressed
multipart/x-zip
mrinject
To be more specific, the only extensions that will work on `$config['allowed_type']` are gif, jpg, jpeg, png, and jpe. As for what CodeIgniter expects you to put in `$config['allowed_type']`, you can check out `system/application/config/mimes.php`.
jimyi
Ok, I set the variable like this:$config['allowed_types'] = 'application/zip|application/x-zip|application/x-zip-compressed|application/octet-stream|application/x-compress|application/x-compressed|multipart/x-zip';And I recieve: "The filetype you are attempting to upload is not allowed."
Christoffer
+1  A: 

I solved it using the code provided by "kofic" here: http://codeigniter.com/forums/viewthread/113029/

Christoffer