Problem uploading PDF Files |
[eluser]farrelley[/eluser]
The problem with PDF seems to be the preg_replace function in the Uploads.php Library. if you echo out the $_FILES['userfile']['type'] you will get \"application/pdf\" The String is escaped! So this doesn't match anything int he mime type class. In the do_upload() method in the Uploads Class you can see there is code that is supposed to do a regular expression replace Code: $this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']); This expression isn't working correctly. What I have done as a quick fix is to just do a str_replace() on the '\"' combination. just comment out the preg_replace and add this. Code: $this->file_type = str_replace('\"', '', $_FILES[$field]['type']); Hope this works for you. Will post update for preg_replace() later.
[eluser]anthropos9[/eluser]
I've tried every fix I can find for this problem and nothing seems to work. I've tried on both Safari 4 and FF 3.5. I'm on a Mac so IE isn't an option. Does anyone have any other suggestions on how I can get this to work? I really need to be able to upload PDF files. Thanks. Below is my code - maybe some fresh eyes can see a problem. The file type being listed by $_FILES[$field_name]['type'] is application/pdf with no quotes or commenting out. Code: function _pdfUpload(){ In my mimes file this is the line for PDF: Code: 'pdf' => array('application/pdf', 'application/x-pdf', 'application/x-download','application/download','binary/octet-stream'),
[eluser]Spicer[/eluser]
Not sure if this is a bug or not. But is solved my problem. It looks like in Upload.php the following code is used to test if the file is an image. I don't have great knowledge of how image files work but I was having this return FALSE on a .pdf and a .php file. After doing a print_r(getimagesize($this->file_temp)); I determine that both these files were being read as images in getimagesize. I just commented out that chunk of code and kept going. Code: One Line 566ish in Upload.php
[eluser]Spicer[/eluser]
To follow that up. Here is two print_r's from Code: $data = array('upload_data' => $this->upload->data()); After I completed the upload. As you can see it thinks the file has image data. Code: Array
[eluser]dirkpostma[/eluser]
For people that read this forum with (about) the same problem: there is a bug in Upload class (CI 1.7.2) that can cause this error, see: http://codeigniter.com/bug_tracker/bug/6780/ Quick solution without patching CI is to set non-image types in front of allowed_types. So instead of "jpg|gif|pdf|zip", you should use "pdf|zip|jpg|zip".
[eluser]tison[/eluser]
I had to do the following: Code: 'pdf' => array('application/pdf', 'application/x-pdf', 'text/html'),
[eluser]benoa[/eluser]
Editing the config/mimes.php seems to be the best way to get rid of this problem. Keep security in mind though... print_r($this->upload->data()); and then see if the file_type exists for the according extension in mimes.php. If not, just add it and it will work. Putting the image types don't work for me (I allow a large set of types), and hacking the Upload.php class doesn't work as well.
[eluser]marcello romani[/eluser]
Hallo everybody, I have the same problem: I cannot upload PDF files because the mime type is not allowed even though I have it in allowed_types: Code: $upload_config['allowed_types'] = 'pdf|txt|jpg|png'; I see the problem with FF 3.5.7 on Ubuntu 9.10 (the exact user agent string is "Mozilla/5.0 (X11; U; Linux i686; it; rv:1.9.1.7) Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7"). However, I can upload pdfs just fine with IE 7 on Windows XP SP3 (exact IE version is 7.0.5730.13). I have used Wireshark and I found something interesting: FF sends the file as text/html, while IE sends the same file as application/pdf. So it seems it's not a CI bug, but rather a FF one! Partial dump of FF session: Quote:POST /~marcello/php/ci_doctrine_upload/index.php/upload/submit HTTP/1.1 Partial dump of IE session: Quote:POST /~marcello/php/ci_doctrine_upload/index.php/upload/submit HTTP/1.1
[eluser]marcello romani[/eluser]
[quote author="tison" date="1258175261"]I had to do the following: Code: 'pdf' => array('application/pdf', 'application/x-pdf', 'text/html'), Despite my previous findings, this workaround didn't work for me. Instead I had to do: Code: 'pdf' => array('application/pdf', 'application/x-pdf', 'application/force-download') |
Welcome Guest, Not a member yet? Register Sign In |