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 > Mac OS X > Downloading a file using php

Downloading a file using php
Thread Tools
Mac Elite
Join Date: Jul 2000
Location: Washington, DC
Status: Offline
Reply With Quote
Jan 5, 2003, 10:40 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, 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?



[edit] auto-parse urls messed with the second php code block
(Last edited by krove; Jan 5, 2003 at 11:52 PM. )

How did it come to this? Goodbye PowerPC. | sensory output
     
krove  (op)
Mac Elite
Join Date: Jul 2000
Location: Washington, DC
Status: Offline
Reply With Quote
Jan 7, 2003, 01:12 AM
 
ok, thought I had checked permissions (twice no less), but alas, they weren't enough.

problem solved.

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 12:52 AM.
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