curl-and-php
RE: curl-and-php Digest, Vol 28, Issue 5 Subj: a download
Date: Fri, 7 Dec 2007 17:34:57 +0000
Here is some php code that I use to open an file handler and write the results of a Curl fetch to a file. The name of the file here is the current time-stamp but a user-input name should be possible.
$now = time();
$filename = $now.".txt";
$outfile = @fopen($filename, "w+") or die("Error opening file");
@fwrite($outfile, "<url>".$target."</url>\n") or die("Error writing to file (1).\n");
@fwrite($outfile, $title."\n") or die("Error writing to file (2).\n");
if(strlen($content)>0){
@fwrite($outfile, $content) or die("Error writing to file (3).\n");
}
fclose($outfile);
Ralph
> From: curl-and-php-request_at_cool.haxx.se
> Subject: curl-and-php Digest, Vol 28, Issue 5
> To: curl-and-php_at_cool.haxx.se
> Date: Fri, 7 Dec 2007 12:00:01 +0100
>
> Send curl-and-php mailing list submissions to
> curl-and-php_at_cool.haxx.se
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
> or, via email, send a message with subject or body 'help' to
> curl-and-php-request_at_cool.haxx.se
>
> You can reach the person managing the list at
> curl-and-php-owner_at_cool.haxx.se
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of curl-and-php digest..."
>
>
> Today's Topics:
>
> 1. PHP libcURL : Windows can upload file up to 2 MB but Unix is
> uploading only 100kb (desai shweta)
> 2. Re: PHP cURL : File upload is sucessful in Windows but not in
> UNIX. (Morgan Galpin)
> 3. a download (Colleen R. Dick)
> 4. Re: PHP libcURL : Windows can upload file up to 2 MB but Unix
> is uploading only 100kb (varun krishnan)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 6 Dec 2007 21:26:20 +0000
> From: desai shweta <setuset_desai_at_hotmail.com>
> Subject: PHP libcURL : Windows can upload file up to 2 MB but Unix is
> uploading only 100kb
> To: <curl-and-php_at_cool.haxx.se>
> Message-ID: <BAY121-W2DA937F3DD3B200162ABA9F6F0_at_phx.gbl>
> Content-Type: text/plain; charset="iso-8859-1"
>
>
> I have strange environment problem with PHP/libCurl.
>
> Windows Version:
> PHP : 5.2.0
> libCurl :7.16.0
> curl: 7.16.0
>
> Unix Version:
> PHP : 5.1.4
> libCurl: 7.15
> curl: 7.15
>
> When I try to upload 2MB file from windows m/c to remote server I am able to get confirmation.
> But same file I am not able to Upload from Unix.However, 120kb file size I am able to upload from Unix.
>
> The post is multipart and it is https transfer. My upload script is below.
>
> $postData = array();$postData[ '__VIEWSTATE' ] = $viewStateVari; $postData[ 'flUpl' ] = $uploadFile;$postData[ 'btnSubmit' ] = 'Submit';
> $ch = curl_init();curl_setopt($ch, CURLOPT_URL,$STEPSEVENURL);curl_setopt($ch, CURLOPT_VERBOSE, 1);curl_setopt($ch, CURLOPT_USERAGENT, $agent);curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS,$postData);curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);curl_setopt($ch, CURLOPT_REFERER, $reffer);curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
>
> Thanks & Regards,
> SMD
> _________________________________________________________________
> Post ads for free - to sell, rent or even buy.www.yello.in
> http://ss1.richmedia.in/recurl.asp?pid=186
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://cool.haxx.se/pipermail/curl-and-php/attachments/20071206/09ea6f7e/attachment-0001.htm
>
> ------------------------------
>
> Message: 2
> Date: Thu, 06 Dec 2007 14:23:35 -0800
> From: Morgan Galpin <morgan_at_atsourceinc.ca>
> Subject: Re: PHP cURL : File upload is sucessful in Windows but not in
> UNIX.
> To: curl with PHP <curl-and-php_at_cool.haxx.se>
> Message-ID: <47587667.7070404_at_databyte.com>
> Content-Type: text/plain; charset=windows-1252; format=flowed
>
> Hi desai,
>
> It seems the problem may have to do with the file / file name. I would
> try the following:
>
> 1. Make sure that when you specify $uploadFile, which appears to come
> directly from $argv[1], that you use a full case-sensitive path
> and file name. The case-sensitive part is a distinct difference
> between windows and unix.
> 2. Make sure all of your path names use the forward slash, /, and not
> the backslash, \. The forward slash will work in windows and unix,
> but the backslash will only work in windows. The backslash also
> has special meaning in php "" type strings, so use the forward
> slash where you can, or if you must, escape it using two backslashes.
> 3. Make sure that the file you are trying to upload is readable by
> the user that runs the php script. This may not be the problem in
> your case, but it is good to check.
> 4. The file you are uploading for windows seems to be a few kilobytes
> larger than the unix one. Are they the same file? Did the unix
> version have its line endings modified from the windows version?
> Does the IIS server you are sending it to not like the unix
> version of the file? Make sure the file you are sending is in a
> format the server is expecting.
>
> Give that a try and let us know how it goes,
> Morgan Galpin.
>
> desai shweta wrote:
> >
> > Hi Everyone,
> >
> >
> >
> > I am not able to Upload the file to remote server in UNIX environment.
> > The same PHP-cURL script is working fine in Windows environment.
> >
> >
> >
> > I have attached my PHP script and logs with this email.
> >
> >
> >
> > First 4 screens traverse including login is working fine in both
> > environment.
> >
> > Only uploading part is not working in UNIX.
> >
> >
> >
> > I am not sure if I am missing something. Steps of upload are written
> > below.
> >
> >
> >
> > Version of PHP : 5.1.4
> >
> > Version of cURL: 7.15
> >
> >
> >
> >
> >
> > $STEPSEVENURL = 'https:\\www.PPPP.com\F\UplFile.aspx';
> >
> >
> >
> > $reffer = 'https:\\www.PPPP.com\F\UplFile.aspx';
> >
> >
> >
> > $postData = array();
> >
> > $postData[ '__VIEWSTATE' ] = $startposition_6;
> >
> > $postData[ 'Uplod' ] = $uploadFile;
> >
> > $postData[ 'Submit' ] = 'Submit';
> >
> >
> >
> >
> >
> > $ch = curl_init();
> >
> > curl_setopt($ch, CURLOPT_URL,$STEPSEVENURL);
> >
> > curl_setopt($ch, CURLOPT_VERBOSE, 1);
> >
> > curl_setopt($ch, CURLOPT_USERAGENT, $agent);
> >
> > curl_setopt($ch, CURLOPT_POST, 1);
> >
> > curl_setopt($ch, CURLOPT_POSTFIELDS,$postData);
> >
> > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> >
> > curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
> >
> > curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
> >
> > curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
> >
> > curl_setopt($ch, CURLOPT_REFERER, $reffer);
> >
> > curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
> >
> > curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
> >
> >
> >
> > \\output to file
> >
> > $fp = fopen ($step6file, 'w');
> >
> > curl_setopt ($ch , CURLOPT_FILE, $fp);
> >
> >
> >
> > \\execute
> >
> > $result =curl_exec ($ch );
> >
> >
> >
> > \\ print errors
> >
> > print_r(curl_getinfo($ch));
> >
> > echo '\n\ncURL error number:' .curl_errno($ch);
> >
> > echo '\n\ncURL error:' . curl_error($ch);
> >
> >
> >
> > \\close resources
> >
> > curl_close ($ch );
> >
> > fclose ($fp);
> >
> >
> >
> > Your input will be very appreciated.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > Thanks & Regards,
> >
> > SMD
> >
> >
> >
> >
> > ------------------------------------------------------------------------
> > Live the life in style with MSN Lifestyle. Check out! Try it now!
> > <http://content.msn.co.in/Lifestyle/Default>
> > ------------------------------------------------------------------------
> >
> > _______________________________________________
> > http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>
>
> ------------------------------
>
> Message: 3
> Date: Thu, 06 Dec 2007 16:47:51 -0800
> From: "Colleen R. Dick" <platypus_at_proaxis.com>
> Subject: a download
> To: curl with PHP <curl-and-php_at_cool.haxx.se>
> Message-ID: <1196988472.6005.168.camel_at_localhost.localdomain>
> Content-Type: text/plain
>
> I have managed to log into a site and make it do a query and have my
> custom data appear on a dynamic web page (if I choose to print out the
> results of curl_exec.)
> There is a BUTTON on that page that allows you to download a spreadsheet
> of that data. You can't just fetch the file with wget or curl because
> I'm sure it doesn't live anywhere under document root so it wouldn't
> have a URL. you have to submit the form to ask the server for it and it
> downloads it as some sort of attachment with a dialog when you do it
> manually. Obviously I want to set it up so it just falls into some
> file handle. I checked what the button does, it just calls a
> javascript to set up some other post variables before submitting the
> form.
>
> Here is the submit button:
>
> <input class="button" type="button" value="Export All Data"
> onclick="exportFile(); return(false);
>
> Here is the javascript exportFile:
>
> function exportFile()
> {
> document.RptForm.pageno.value = 1;
> document.RptForm.expflag.value = 1;
> document.RptForm.rptaction.value = "qryordertime";
>
> document.RptForm.pagefile.value = "temp1196982492309.1040408.1";
>
> exptype = document.RptForm.exptype.options[document.RptForm.exptype.selectedIndex].value;
> if (exptype=="csv") document.RptForm.expfile.value="exp_ordercsv.xsl";
> else if(exptype=="xml") {
> document.RptForm.target = "_blank";
> document.RptForm.expfile.value="exp_orderxml.xsl";
> }
> document.RptForm.submit();
> document.RptForm.target = "_self";
> }
>
> So what I did was hard code all the post variables like the javascript does them
> and submits the form.
> It doesn't throw any errors, I don't think. I made it print out curl_getinfo
> Array
> (
> [url] => https://www.linkpointcentral.com/lpc/servlet/LPCReport
> [content_type] => text/html; charset=ISO-2259-1
> [http_code] => 200
> [header_size] => 153
> [request_size] => 665
> [filetime] => -1
> [ssl_verify_result] => 0
> [redirect_count] => 0
> [total_time] => 2.981608
> [namelookup_time] => 0.000101
> [connect_time] => 0.113942
> [pretransfer_time] => 0.529531
> [size_upload] => 0
> [size_download] => 0
> [speed_download] => 0
> [speed_upload] => 0
> [download_content_length] => 0
> [upload_content_length] => 0
> [starttransfer_time] => 2.981528
> [redirect_time] => 0
> )
>
> It names the document rpt*******.csv but I would like it to download into a file name of my choice.
> To that end I have set up and opened a filehandle but it always ends up of size zero, which makes sense if
> I don't know how to tell CURL to use it. Where is the document going if anywhere?
> It is not in tmp or in my web tree. I'm sorry if I am stupid but I have really looked very hard for the answer.
> All I see is little examples to use Curl to download a file where it has a URL. I know how to do that.
>
>
>
> ------------------------------
>
> Message: 4
> Date: Fri, 7 Dec 2007 10:03:47 +0530
> From: "varun krishnan" <varunkrish_at_gmail.com>
> Subject: Re: PHP libcURL : Windows can upload file up to 2 MB but Unix
> is uploading only 100kb
> To: "curl with PHP" <curl-and-php_at_cool.haxx.se>
> Message-ID:
> <a791cae80712062033w412216bv99effa04146f3e1_at_mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> check you php memmory limits..
>
> please use phpinfo() to check the same.
>
> regards,
>
> Varun
>
> On Dec 7, 2007 2:56 AM, desai shweta <setuset_desai_at_hotmail.com> wrote:
>
> > I have strange environment problem with PHP/libCurl.
> >
> > Windows Version:
> > PHP : 5.2.0
> > libCurl :7.16.0
> > curl: 7.16.0
> >
> > Unix Version:
> > PHP : 5.1.4
> > libCurl: 7.15
> > curl: 7.15
> >
> > When I try to upload 2MB file from windows m/c to remote server I am able
> > to get confirmation.
> > But same file I am not able to Upload from Unix.However, 120kb file size I
> > am able to upload from Unix.
> >
> > The post is multipart and it is https transfer. My upload script is below.
> >
> > $postData = array();
> > $postData[ '__VIEWSTATE' ] = $viewStateVari;
> > $postData[ 'flUpl' ] = $uploadFile;
> > $postData[ 'btnSubmit' ] = 'Submit';
> > $ch = curl_init();
> > curl_setopt($ch, CURLOPT_URL,$STEPSEVENURL);
> > curl_setopt($ch, CURLOPT_VERBOSE, 1);
> > curl_setopt($ch, CURLOPT_USERAGENT, $agent);
> > curl_setopt($ch, CURLOPT_POST, 1);
> > curl_setopt($ch, CURLOPT_POSTFIELDS,$postData);
> > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
> > curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
> > curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
> > curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
> > curl_setopt($ch, CURLOPT_REFERER, $reffer);
> > curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
> > curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
> >
> >
> > Thanks & Regards,
> > SMD
> >
> > ------------------------------
> > Post free auto ads on Yello Classifieds now! Try it now!<http://ss1.richmedia.in/recurl.asp?pid=255>
> >
> > _______________________________________________
> > http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
> >
> >
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: http://cool.haxx.se/pipermail/curl-and-php/attachments/20071207/41e6456e/attachment-0001.htm
>
> ------------------------------
>
> _______________________________________________
> curl-and-php mailing list
> curl-and-php_at_cool.haxx.se
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>
> End of curl-and-php Digest, Vol 28, Issue 5
> *******************************************
_________________________________________________________________
You keep typing, we keep giving. Download Messenger and join the i’m Initiative now.
http://im.live.com/messenger/im/home/?source=TAGLM
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-12-07