I'm experiencing a very odd upload problem. Here's the relevant view file:
<form action="http://localhost/index.php/temp/upload/" method="post" enctype="multipart/form-data">
<fieldset>
<input type="file" name="userfile"/>
<input type="submit" value="Upload"/>
</fieldset>
</form>
And here's my temp
controller's upload()
method:
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:
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:
'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. Are these browser or server issues?
if you need the simple way to solve this,there is an easy solution for it. open "system/libraries/Upload.php" file
On the server where you have uploaded the .wmv file, execute the following PHP code
Save the code as mime.php
Also check PHP_VERSION in other development machines. finfo_open is introduced in PHP 5.3. The development machine where upload is working may have an older version of PHP or it may have right mime type for the wmv.
I've recently had some very similar problems with the Codeigniter's Upload Class.
The *allowed_types* doesn't seem to be working. For example, I wanted to allow .PNG images to be uploaded, but it wouldn't allow them through it's filter. I ended up investigating it further. I allowed all file types to be temporarily uploaded, I uploaded a .PNG, and then dumped the upload data ($this->upload->data());). For some reason, it thought the MIME type was text/plain! This might be related to your problem.
There are some solutions to this I found surfing some forums where you can modify/extend the class or core, but they didn't work for me -- sorry. I believe it's a Codeigniter Core bug (I think the issue has already been opened with EllisLabs). I ended up hard-coding the damn thing anyways! Well, I hope this helps you some.
Basic example/work-around,
Edit: Formatting/Grammar
$config["allowed_types"] ="*";