Welcome Guest, Not a member yet? Register   Sign In
Problem uploading PDF Files
#21

[eluser]marcello romani[/eluser]
For a reason I still don't understand, FF is now uploading the file as "application/force-download".

Quote:POST /~marcello/php/ci_doctrine_upload/index.php/upload/submit HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; U; Linux i686; it; rv:1.9.1.7) Gecko/20100106 Ubuntu/9.10 (karmic) Firefox/3.5.7
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: it-it,it;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost/~marcello/php/ci_doctri...php/upload
Cookie: ci_session=a:4:{s:10:"session_id";s:32:"75642ca75abf2e25a099a4c0fa3e3d42";s:10:"ip_address";s:7:"0.0.0.0";s:10:"user_agent";s:50:"Mozilla/5.0+(X11;+U;+Linux+i686;+it;+rv:1.9.1.7)+G";s:13:"last_activity";s:10:"1262956976";}bb9cd2413e4da9fe2d982d81c1dd00b9
Content-Type: multipart/form-data; boundary=---------------------------1040701901235425247461644255
Content-Length: 291318


-----------------------------1040701901235425247461644255
Content-Disposition: form-data; name="filename"; filename="sigmetrics09.pdf"
Content-Type: application/force-download

%PDF-1.2
%....
5 0 obj
<</Length 6 0 R/Filter /FlateDecode>>
stream
x..}[....f.>j.#............k....=.......$.DjE.CI<[email protected].:..SQ]@..D...d}.d]....../.~.>.-....7.(..I....._>.....'*,........V.I..K.?...D...'.v.....>......:....`..8.tP.Z...p.(o.?|{.^......$....Q/._..{..:.x....u....:........;......xR..*..kl.R4./j+u.3.......A..7.....gp..

Therefore, adding "application/force-download" to the list of mime-types associated with "pdf" solves the problem.
#22

[eluser]marcello romani[/eluser]
Sorry to post again, but I think I found the problem.

It was not a CI issue after all. I had an entry in mimeTypes.rdf that where pdf files were associated with application/force-download mime-type.

Deleting that RDF entry totally solved the problem.

Quote:Content-Disposition: form-data; name="filename"; filename="sigmetrics09.pdf"

Content-Type: application/pdf

HTH
#23

[eluser]Sulik[/eluser]
there is a simple solution to your problem... dont use the codeignigter upload class... create your own upload based on php hardcode, so you have total control of the uploading functionalities. Ive implemented an upload, where it can accept all extensions except exe's, vbscript etc., you can search on google and find a hack there but it all leads to complicated stuff but dont work. But by making my own upload, ive done it with just a few minutes no sweat. Smile
#24

[eluser]marcello romani[/eluser]
[quote author="Sulik" date="1265166945"]there is a simple solution to your problem... dont use the codeignigter upload class... create your own upload based on php hardcode, so you have total control of the uploading functionalities. Ive implemented an upload, where it can accept all extensions except exe's, vbscript etc., you can search on google and find a hack there but it all leads to complicated stuff but dont work. But by making my own upload, ive done it with just a few minutes no sweat. Smile[/quote]


Thank you for the tip. I'll look into that.

May I ask you to post some hints about where to begin to implement a system-wide Upload class meant to replace CI's one ? Thank you.
#25

[eluser]Wazzu[/eluser]
[quote author="dirkpostma" date="1255393173"]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".[/quote]
You saved me! thanks!
#26

[eluser]voscom[/eluser]
Not sure if this is a bug or not.
#27

[eluser]wdcmatt[/eluser]
I had the exact same problems. I could not upload PDF's for some reason. I tried all the fixes here, and only one worked (thanks farrelley). Modifying the Upload.php class, however to maintain compatibility I created an extension of the Upload class (MY_Upload.php) that fixed the problem....

I have attached the file I created (as a zip). Place this in your ./system/application/library folder, You may have to modify the file name if you changed the section of code in the config.php file:

Code:
$config['subclass_prefix'] = 'MY_';

If you changed that line you will have to modify the file name accordingly, otherwise this should fix the problem. It did for me at any rate.

I simply overwrote the old do_upload method with the exact same thing as before with 2 lines changed, I commented out line 68

Code:
$this->file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES[$field]['type']);

and added farrelley's code:

Code:
$this->file_type = str_replace('\"', '', $_FILES[$field]['type']);
#28

[eluser]prestondocks[/eluser]
I followed the instructions below and this sorted out the problem I had. I was not able to upload any office files they were all being reported as application/octet-stream. Even after adding that mime type to the ppt and doc arrays in mimes.php I was still getting the incorrect file type message. It does seem that the upload module is treating every file as though it is an image.

Thanks
[quote author="Spicer" date="1255246088"]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

/*
if (in_array($val, $image_types))
            {
                if (getimagesize($this->file_temp) === FALSE)
                {
                    return FALSE;
                }
            }
*/
[/quote]
#29

[eluser]LTFMIKE[/eluser]
Hi Everybody. I would like also to share my problem here.I tried to Upload file using uploading class and it's works quite fine.Unfortunately, if I upload file with particular filename like for exemple "1_file_rue_hôpital.pdf"
it will be set correctly in database like : "1_file_rue_hôpital.pdf" but
filename of the file itself is not correctly saved on the server.I obtain file like :
"rue_hôpital.pdf"

I search many topic to find a solution but I haven't found something helpful yet.

Hope you guys help me..;

here is my upload controller configuration :
Code:
$filePath=$this->createArboGen($arbo);
        $config['upload_path']         = $filePath;
        $config['allowed_types']     = 'pdf|xls|doc';
        $config['max_width']          = '1024';
        $config['max_height']          = '768';
        $config['overwrite']        = 'TRUE';
        $config['remove_spaces']    = 'TRUE';
        $data['erreur']                = $this->erreur;        
        
        $this->setFile($dataFile,'',$fileTypeId);
        $this->insertFile();
        $config['file_name']        = $this->file_id ."_";
#30

[eluser]LTFMIKE[/eluser]
It's Ok,
I found solution by using str_replace in my upload helper.
here is my example :
Code:
$Output_data = $this->_prep_filename($_FILES[$field]['name']);
$Decrypter_variables =  array("ê","ô", "â", "û", "@", "'","(",")");
$Variables_assign       =  array("e","o", "a", "u", "_", "_","_","_");




Theme © iAndrew 2016 - Forum software by © MyBB