CodeIgniter Forums
[Upload Class] Problem using custom file extension - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: [Upload Class] Problem using custom file extension (/showthread.php?tid=22407)

Pages: 1 2


[Upload Class] Problem using custom file extension - El Forum - 09-08-2009

[eluser]metalking[/eluser]
Hello,

I've tried to use the File Uploading class in order to upload files with a custom extension .uvc. The MIME type is "text/plain" just like a .txt.
I've added a line in my config/mimes.php file, just below the 'txt'-one.
I'm doing the upload with this config : $config['allowed_types'] = 'uvc';

The class keeps saying that the file is not allowed. But if I change my file extension to .txt, and change the $config['allowed_types'] to 'txt' also, then it works... Both have exactly the same MIME type in the config/mimes.php ...

Does anyone have an idea of how to solve this problem?

Thanks!


[Upload Class] Problem using custom file extension - El Forum - 09-09-2009

[eluser]metalking[/eluser]
Up?
If anyone could read this.. I'm supposed to launch the website tomorrow..


[Upload Class] Problem using custom file extension - El Forum - 09-09-2009

[eluser]BrianDHall[/eluser]
I'm working on file uploads right at the moment too.

OK, so to be clear, in config/mimes.php you have something like:

Code:
$mimes = array(    'uvc'    =>'text/plain');

Right?

Now upload your file using any method, and when you do run a var_dump($_FILES) - what is the 'type' coming back as, text/plain?

I don't see why that wouldn't work, but if it doesn't worst-case you'll need to google for a quick manual file upload script you can use so you can at least get this working while you figure out what's going wrong.

I don't see any way in the upload class to bypass the allowed filetype or set it to 'any', either, I'm afraid.


[Upload Class] Problem using custom file extension - El Forum - 09-09-2009

[eluser]BrianDHall[/eluser]
Also you may wish to look at this: file helper class

Quote:get_mime_by_extension('file')

Translates a file extension into a mime type based on config/mimes.php. Returns FALSE if it can't determine the type, or open the mime config file.

$file = "somefile.png";
echo $file . ' is has a mime type of ' . get_mime_by_extension($file);
Note: This is not an accurate way of determining file mime types, and is here strictly as a convenience. It should not be used for security.

You might run that on an instance of your uvc file as well to ensure your mime file is setup and working correctly.


[Upload Class] Problem using custom file extension - El Forum - 09-09-2009

[eluser]metalking[/eluser]
Thanks for your answer! I'll try this in the next couple of hours and post back!


[Upload Class] Problem using custom file extension - El Forum - 09-10-2009

[eluser]metalking[/eluser]
Hi guys !

I verified, and the mime type for my file is 'text/plain' as expected. This means that CI has access to my config/mimes.php file and that everything should be fine..

So.. any idea?

Thanks in advance!


[Upload Class] Problem using custom file extension - El Forum - 09-10-2009

[eluser]BrianDHall[/eluser]
Hm...well for the last 3 days I've been working on custom file upload functions (and a multi-file uploader using flash/javascript that saves images into the database for dynamic recreation and with multiple associations... which was an unexpectedly tricky), so I already have basic test functions in place. If you'd like to send me a sample uvc file I'll happily test it on my system and report what I find.

I found the key to figuring out what was going on with mine was using a debugger, stepping line by line through the code, and Stepping Into the file uploader class to see what went wrong. I ended up running into a MIME problem myself (uploading an image with flash does not result in an image mime, but an application/octetstream mime...tricky!) Smile


[Upload Class] Problem using custom file extension - El Forum - 09-10-2009

[eluser]InsiteFX[/eluser]
You may have to add it to your .htaccess file

Enjoy
InsiteFX


[Upload Class] Problem using custom file extension - El Forum - 09-10-2009

[eluser]Aken[/eluser]
This is likely a bug that has to do with image checking inside the Upload class. See this thread for a fix!


[Upload Class] Problem using custom file extension - El Forum - 09-10-2009

[eluser]metalking[/eluser]
For BrianDHall : basically it's just a txt file renamed with the extension uvc. I can reproduce the bug doing so. Anyway, I post one here (I had to add .txt at the end of the file in order to post it on the forums. You can just rename the file.)
And for your application/octetstream, you should have asked me, I had the same problem with a flash uploader last year ! ^^

For InsiteFX : already done so. The folder containing my uploaded files is accessible.

Aken : I'll try this! Thanks

Thanks for your answers, I hope this will work !
Bye