Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Downloading a file using php + curl == no success

Downloading a file using php + curl == no success
Thread Tools
Mac Elite
Join Date: Jul 2000
Location: Washington, DC
Status: Offline
Reply With Quote
Jan 5, 2003, 11:47 PM
 
Ok, I'm fairly familiar with php, etc, but I am for the first time trying to get it to download a file for me. Using the example found in the php manual on http://www.php.net, this is what I'm using:

[php]<?php
$ch = curl_init ("http://www.apple.com/");
$fp = fopen ("apple_homepage.txt", "w");
curl_setopt ($ch, CURLOPT_FILE, $fp);
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
fclose ($fp);
?>[/php]

Unfortunately, everytime I run this under apache (os x 10.2 default version, php 4.2.3), I don't get a file called apple_homepage.txt as expected, but rather the apple.com homepage outputted to the browser. Can anyone tell me why I'm not getting the expected result?

I even tried just running the following without success (no file created):
[php]<?php
$a = `curl http://www.apple.com -o apple_homepage.txt`;
echo 'something should have happened';
?>[/php]

Unfortunately, nothing happened here either. Why?


How did it come to this? Goodbye PowerPC. | sensory output
     
Grizzled Veteran
Join Date: Jun 2001
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jan 6, 2003, 02:43 AM
 
It looks fine... is the directory writable? (i.e. had a 'chmod 777' on it?) If it isn't, perhaps the cURL function gives up trying to write the file and just defaults the output to the browser?

I can't see the 2nd example doing anything - all you've done is set a variable! Is there a line of code missing there?
Computer thez nohhh...
     
krove  (op)
Mac Elite
Join Date: Jul 2000
Location: Washington, DC
Status: Offline
Reply With Quote
Jan 6, 2003, 08:42 PM
 
You're right...I thought the permissions were correct, but after chmod 777 the directory (sub-directory inside /Library/WebServer/Documents) it worked as expected.

As for the second code not actually doing anything: it uses the back-tick operator (not single quotes), which is the same as the shell_exec() function.

Thanks again!

How did it come to this? Goodbye PowerPC. | sensory output
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:01 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2