Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter: “The filetype you are attempting to upload is not allowed.”
#1

[eluser]CodeIgniterNewbie[/eluser]
I'm experiencing a very odd upload problem. Here's the relevant view file:

Code:
<form action="http://localhost/index.php/temp/upload/" method="post" enctype="multipart/form-data">
     <fieldset>
      &lt;input type="file" name="userfile"/&gt;
      &lt;input type="submit" value="Upload"/&gt;
     </fieldset>
    &lt;/form&gt;
And here's my `temp` controller's `upload()` method:

Code:
public function upload()
    {
     $config['upload_path']   = FCPATH . 'uploads' . DIRECTORY_SEPARATOR;
     assert(file_exists($config['upload_path']) === TRUE);
     $config['allowed_types'] = 'avi|mpg|mpeg|wmv|jpg';
     $config['max_size']      = '0';
    
     $this->load->library('upload', $config);
     if ($this->upload->do_upload('userfile') === FALSE)
     {
      // Some error occured
      var_dump($this->upload->display_errors('', ''));
      var_dump($_FILES);
     }
     else
     {
      // Upload successful
      var_dump($this->upload->data());
     }
    }

When I upload an AVI video, everything works fine. When I upload, say, a WMV video, I get the following var dumps:

Code:
string 'The filetype you are attempting to upload is not allowed.' (length=57)
    
    array
      'userfile' =>
        array
          'name' => string 'wmv.wmv' (length=7)
          'type' => string 'video/x-ms-wmv' (length=14)
          'tmp_name' => string 'C:\wamp\tmp\php2333.tmp' (length=23)
          'error' => int 0
          'size' => int 83914
The "wmv" extension is being interpreted as the MIME type: `video/x-ms-wmv`. This should be fine since my config/mimes.php has the following:

Code:
'wmv' =>  array('video/x-ms-wmv', 'audio/x-ms-wmv')

It's a similar situation when I try uploading other files. So far, the only one that seems to work is my test AVI video.

Any ideas what might be wrong?

UPDATE 1:

One my machine, only AVI uploads. On another developer's machine, no files upload. On yet another developer's machine, all supported files upload. Is this a browser or server issues?
#2

[eluser]Chathuranga Tennakoon[/eluser]
this might be a problem of the LAMP/WAMP/XAMP or any other server that you are using. please check the php.ini file with below configuration.
Code:
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = "e:/wamp/uploads"

; Maximum allowed size for uploaded files.
upload_max_filesize = 8M

hope that might help!

#3

[eluser]CodeIgniterNewbie[/eluser]
All those seem to be set correctly. Upload actually used to work, then I noticed this problem just recently. Not sure what could have changed in the code or server.
#4

[eluser]Chathuranga Tennakoon[/eluser]
if the problem occurred recently, that might be due to the configuration issues n the server side(most probably). since it is working and behaving in three developers' machines in total different ways, the error may rely on the server side. better to check the server side configuration rather than struggling with your code.
#5

[eluser]Narf[/eluser]
Try dumping $this->upload->file_type - this is the actual MIME type detected by the server and the one that's used for validation, not the one that's in $_FILES.
#6

[eluser]thisischris[/eluser]
I have also recently gotten that error. I think someone forget to select a file and hit upload anyway. Now each time it gives me the error.

I found this in the log: ERROR - 2012-03-25 11:22:36 --&gt; Severity: Notice --&gt; Undefined index: tmp_path /homepages/14/xxxx/htdocs/xxx/system/libraries/Upload.php 1058

which is this block: [codeif (DIRECTORY_SEPARATOR !== '\\' && function_exists('exec'))
{
$output = array();
@exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);
if ($return_code === 0 && strlen($output[0]) > 0) // A return status code != 0 would mean failed execution
{
$this->file_type = rtrim($output[0]);
return;
}
}[/code]

This line basically: @exec('file --brief --mime-type ' . escapeshellarg($file['tmp_path']), $output, $return_code);

It works perfectly in my localhost (windows) however the server is definitely linux.
#7

[eluser]InsiteFX[/eluser]
Check your server mime types, not all hosting providers install all mime types!

You may need to add the mime type through your CPanel etc.
#8

[eluser]rickster[/eluser]
I seem to have the same problem. On a hosting account with only doc, pdf and docx allowed.
pdf uploads fine but the doc and docx I got 'not allowed'. mime-types are setup and correct, this really has me stumped.

Code:
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';
  $config['allowed_types'] = 'doc|pdf|docx';
  $config['max_size'] = '200';
  $this->load->library('upload', $config);
  $this->upload->do_upload();

Any more suggestions are most welcome.
#9

[eluser]skunkbad[/eluser]
[quote author="rickster" date="1332854809"]I seem to have the same problem. On a hosting account with only doc, pdf and docx allowed.
pdf uploads fine but the doc and docx I got 'not allowed'. mime-types are setup and correct, this really has me stumped.

Code:
$config['upload_path'] = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';
  $config['allowed_types'] = 'doc|pdf|docx';
  $config['max_size'] = '200';
  $this->load->library('upload', $config);
  $this->upload->do_upload();

Any more suggestions are most welcome. [/quote]

What have you tried to do to debug?
#10

[eluser]jiolasa[/eluser]
I'm having the same problem.

I have an existing app that's worked fine on 2.0.2. I have a simple allowed_types config line:

Code:
$config['allowed_types'] = 'csv'

It's been working fine, as expected. Today I upgraded to 2.1, and one of my servers (running Ubuntu) no longer accepted .CSV files, but the other (not sure what it's running) still accepts them fine. When I rolled back the upgrade, it fixed it, so it's definitely the upgrade that broke it.

I don't even know where to start, but I'm guessing (since my app worked before the upgrade) this is a bug rather than a programming error.. but, who knows.

I can happily provide any test results or code samples. Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB