Results 1 to 8 of 8
  1. #1
    Grandma broke her coccyx! Uncle Rico's Avatar
    Join Date
    May 8th, 2007
    Location
    North Carolina
    Posts
    2,238
    Php Script to Download Web File Not Working
    I have a very simple php script that I call from a cron to grab a 30 meg datafeed file. It creates the file.txt on my local server, but the file has a 0 length. When I put the http address in my browser, the file is found and full of data. Any ideas?

    Code:
    $fdata = file_get_contents("http://blah.com/file.txt"); 
    file_put_contents("/my/home/dir/file.txt", $fdata);

  2. #2
    ABW Ambassador
    Join Date
    January 17th, 2005
    Posts
    530
    You might want to try something like this, it works for me:

    $url = "http://blah.com/file.txt";
    $str = file_get_contents($url);

    $file = fopen("/my/home/dir/file.txt","w+");
    fwrite($file,$str);

  3. #3
    Roll Tide mobilebadboy's Avatar
    Join Date
    January 18th, 2005
    Location
    Mobile, Alabama
    Posts
    1,220
    Are you running PHP 4 or PHP 5? Just curious, file_put_contents is a PHP 5 function.

    Shawn Kerr (.com) | Disney World | SEC Football

  4. #4
    Grandma broke her coccyx! Uncle Rico's Avatar
    Join Date
    May 8th, 2007
    Location
    North Carolina
    Posts
    2,238
    Quote Originally Posted by mobilebadboy
    Are you running PHP 4 or PHP 5? Just curious, file_put_contents is a PHP 5 function.
    It's php5 and I did get it working.

  5. #5
    ABW Ambassador writerguy's Avatar
    Join Date
    January 17th, 2005
    Location
    Springfield, Missouri, USA
    Posts
    3,248
    Quote Originally Posted by SeymourButts
    It's php5 and I did get it working.
    Care to share how you got it working? Personally, I've been looking for a little "quickie" script like this.

    I find I'm making my PHP scripts for getting files and creating tables far too complicated than I need to!
    Generate more fake news.

  6. #6
    ABW Ambassador writerguy's Avatar
    Join Date
    January 17th, 2005
    Location
    Springfield, Missouri, USA
    Posts
    3,248
    NOTE TO MOBILEBADBOY -- Is there any way I can contact you either via PM or email to ask you a quick question?

    (Just PM me as "writerguy" here or email me at gsfreelance at gmail.com. Thanks.)
    Generate more fake news.

  7. #7
    Newbie
    Join Date
    January 19th, 2009
    Posts
    9
    you can try something like:

    wget [url] > /my/home/dir/file.txt

  8. #8
    ABW Ambassador Snib's Avatar
    Join Date
    January 18th, 2005
    Location
    Virginia
    Posts
    5,303
    I started out using the PHP file retrieval functions like the one here, but after running into several random errors like this over the years I've migrated entirely over to wget. It's just much more stable and reliable. Then if wget fails I use curl as a backup retrieval mechanism.

    - Scott
    Hatred stirs up strife, But love covers all transgressions.

  9. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. PHP Script to convert vidio file into FLV
    By rahulcbr in forum Programming / Datafeeds / Tools
    Replies: 12
    Last Post: April 28th, 2008, 09:31 AM
  2. Problems with php datafeed download script
    By steven420 in forum Programming / Datafeeds / Tools
    Replies: 11
    Last Post: November 29th, 2006, 08:17 AM
  3. htaccess focing download of file NOT WORKING
    By Affiliate Ian in forum Programming / Datafeeds / Tools
    Replies: 6
    Last Post: February 18th, 2005, 03:48 PM
  4. How do I insert a PHP script into a .htm file
    By dak142 in forum Programming / Datafeeds / Tools
    Replies: 8
    Last Post: April 2nd, 2004, 06:24 AM
  5. Best to use - Web Merge or another PHP/MySQL script
    By aprillougheed in forum Programming / Datafeeds / Tools
    Replies: 1
    Last Post: February 13th, 2004, 06:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •