473,388 Members | 1,391 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

curl extension downloads 1 byte only from zip files

I have set up a system to download datafeeds in pain text or zipped.
The download part of this system uses the curl extension to download
the files.

All was well when I tested it with various datafeeds in zipped and
unzipped formats until I came to download zipped files from the
affiliate program we are starting with.

I have verified that the datafeeds download properly in Internet
Explorer but interestingly they also fail in Firefox.

Plain text files will download correctly from the same server with the
curl script.

Using curl to download a file results in a 1 byte file. Downloading
with Firefox produces a 4kb corrupted zip file. I have tried multiple
files all with the same result.

A php script appears to be being used to create the zips on the fly?
could this be the cause of the problem?

Any thoughts on this one are much appricated

-Ben

Jul 17 '05 #1
6 3336
On 12 Jul 2005 12:57:35 -0700, "benji" <be*********@gmail.com> wrote:
I have set up a system to download datafeeds in pain text or zipped.
The download part of this system uses the curl extension to download
the files.

All was well when I tested it with various datafeeds in zipped and
unzipped formats until I came to download zipped files from the
affiliate program we are starting with.

I have verified that the datafeeds download properly in Internet
Explorer but interestingly they also fail in Firefox.

Plain text files will download correctly from the same server with the
curl script.

Using curl to download a file results in a 1 byte file. Downloading
with Firefox produces a 4kb corrupted zip file. I have tried multiple
files all with the same result.

A php script appears to be being used to create the zips on the fly?
could this be the cause of the problem?


Minimal example code reproducing the problem?

Example URL?

First place to look would be the Content-type header.

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2
Thanks for the feedback it has helped my understanding of the problem.

Here is a cut down version of the code I am using. Sorry about omitting
the url I don't think the company would be impressed if I posted it in
a public forum.

I have also posted the responce headers below. I think that the
Content-Disposition: attachment; part is the key. I am guessing that
curl is downloading the result of the url (nothing) rather than the
file the headers are pointing to unfortunality I still cant seem to
find any relevent information that explains how curl handles this
situation.

-Ben

$ch = curl_init('url');

$fp = fopen("downloaded.zip", "w");

curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_FILE, $fp);

$downloaded = curl_exec($ch);

curl_close($ch);

fclose($fp);

HTTP/1.1 200 OK
Date: Tue, 12 Jul 2005 23:42:34 GMT
Server: Apache/2.0.46 (Red Hat)
Accept-Ranges: bytes
X-Powered-By: PHP/4.3.2
Set-Cookie: PHPSESSID=ddb9c654715d488d3f6036127b1d624d; path=/
Cache-Control: must-revalidate
Content-Length:
Content-Disposition: attachment; filename=awcsv.zip
Connection: close
Content-Type: application/zip

Jul 17 '05 #3
> Content-Length:
The problem might be in empty Content-Length header field.
You may signal this error to the company providing the data
this way.
Hilarion
Jul 17 '05 #4
Thank you for your help with this problem I will add it to my support
ticket and see if they do anything about it.

Interestingly I have knocked up a solution using fsockopen which works
with the data, although I would still prefer to use curl as I am using
it for other parts of my application.

Best Regards

Ben

Jul 17 '05 #5
> Interestingly I have knocked up a solution using fsockopen which works
with the data, although I would still prefer to use curl as I am using
it for other parts of my application.

You may try using curl_setopt with CURLOPT_WRITEFUNCTION and writing
your own function handling data retrieval.
Hilarion
Jul 17 '05 #6
Thanks for all your help Hilarion,

I will take a look at CURLOPT_WRITEFUNCTION

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Carl Waldbieser | last post by:
I tried to adapt the instructions for building the M2Crypto module (http://sandbox.rulemaker.net/ngps/m2/INSTALL.html) to build a version compatible with Python2.3, but I've had some mixed results....
9
by: Conrad F | last post by:
Hi, If any Microsoft people are listening.... Are there any plans for the new web language called "Curl" to be supported in .NET (ASP.NET)? I ask as Curl represents the first step to true OO...
0
by: Chuck Anderson | last post by:
I am writing a Php script to run on my home PC (Windows) that downloads an Apache access log file and inserts new entries into a database.. The only way I can access these log files is through a...
1
by: ynotssor | last post by:
Hello, can someone please tell me the correct way to use "curl" to complete an online form? I am trying to eventually retrieve my account balance via a cron job that will email me the parsed output...
2
by: lookee | last post by:
Hello all, I have simple PHP application that on one page strarts session and write some information to it. On another page program tryes to fetch information from a third page using cURL. On that...
4
by: sundar22in | last post by:
Hi, How to use CUrl??? What are the libraries to be included using the require_once command?? I wanted to implement Range Header and get a part of file thru HTTP. So found that curl_setopt()...
0
by: xerc | last post by:
I am trying to create a generic function I can call to download all files from a single remote FTP directory -- using CURL. I want to multi-thread it, but need to get the single thread functionality...
12
by: dkurth | last post by:
Hi, I'm running PHP 5.2.3 on Windows 2000 Server with IIS 5. I'm trying to get cUrl working, so in my php.ini file, I have this line: extension_dir ="F:\PHP\ext" And later, I have: ...
5
by: DustinP | last post by:
I have installed PHP5 as ISAPI several times per every single guide I could find in the first 50 pages of results on google.. Server is Windows 2008 runing IIS7, phpinfo works and tells me the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.