Page 1 of 1

cURL file upload problems

Posted: Mon Oct 25, 2010 9:07 am
by iits
Hi,
I'm working on my Joomla-Dropbox Extension: http://www.individual-it.net/en/Joomla/

The extension loads files up to dropbox via cURL. It does it via:

Code: Select all

$data = array('file' => '@/home/user/test.png');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
Dropbox need a signature to accept the data. This signature is calculated out of some values including the submitted filename. My problem is that cURL/PHP send different POST requests:
sometimes is like this:

Code: Select all

------------------------------7d196756d9cb 
Content-Disposition: form-data; name="file"; filename="a-1.txt" 
Content-Type: text/plain 
 
aaaaaaaaaaaaa
 
------------------------------7d196756d9cb-- 
-PHP Version 5.2.10-2ubuntu6.5
-Linux Rechner1-Ubuntu 2.6.31-22-generic #67-Ubuntu SMP Sat Oct 16 19:10:07 UTC 2010 i686
-cURL Information: libcurl/7.19.5 OpenSSL/0.9.8g zlib/1.2.3.3 libidn/1.15

and sometimes like this:

Code: Select all

------------------------------b972a959726a 
Content-Disposition: form-data; name="file"; filename="/home/users/clevoftp/cleverinsert.com/tmp/a-1.txt" 
Content-Type: application/octet-stream 
 
aaaaaaaaaaaaa
 
------------------------------b972a959726a--  
- PHP Version 5.3.2-1+0byte2
- Linux web5 2.6.32-3-686-bigmem #1 SMP Thu Feb 25 06:54:30 UTC 2010 i686
- cURL Information: 7.18.2

because of the different filename (with and without path) I got different signature. I could manage both variants, but I have to be sure that every server send the data in the same way.
Can I force PHP to use the one or the other method?
Or how should I know what way is used?

Re: cURL file upload problems

Posted: Mon Oct 25, 2010 11:09 am
by iits
The problem was a PHP bug: http://bugs.php.net/48962

This is my solution:

Code: Select all

        	if (version_compare(PHP_VERSION, '5.3.1') >= 0 ||
        		(version_compare(PHP_VERSION, '5.3.0') < 0 && version_compare(PHP_VERSION, '5.2.11') >=1 )) 
        		{
        		$arguments=array('file' => '@'.realpath($file).';filename='.JFile::getName($file));
        	}
        	else 
        		$arguments=array('file' => '@'.realpath($file));
so now hopefully every version will send just the name, without the path