1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP error: curl_setopt(): supplied argument is not a valid File-Handle resource

Discussion in 'PHP' started by MarkusJ_NZ, Apr 9, 2007.

  1. #1
    Hi, can someone please help me resolve the following error

    curl_setopt(): supplied argument is not a valid File-Handle resource

    You can see the error message by going here

    http://www.systemsrecovery.info/default.php

    The code I am using is as follows:
    $url ="http://groups.google.com/group/sci.agriculture.beekeeping/feed/rss_v2_0_topics.xml";
    $file = $url;
    $ch = curl_init($file);
    $fp = @fopen("temp.xml", "w");
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);
    $file = "temp.xml";
    $fp = fopen($file, "r");

    Thanks for all/ any help :)
    Regards
    Markus
     
    MarkusJ_NZ, Apr 9, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $fp = @fopen("temp.xml", "w");
    
    PHP:
    Remove the @ and see if the file-opening is successfully.
     
    nico_swd, Apr 9, 2007 IP
  3. MarkusJ_NZ

    MarkusJ_NZ Well-Known Member

    Messages:
    240
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Hi, thanks, I tried that but still no luck. Thanks
    Cheers
    Markus
     
    MarkusJ_NZ, Apr 9, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I didn't expect it to work after the change, but I was hoping for an additional error message caused by fopen(). But I've just seen you're not silencing the error on the second fopen() on the same file, and the errors on your page show that there's no temp.xml file, and PHP can't create it. Try creating it manually in this directory, and make sure it's writable.
     
    nico_swd, Apr 9, 2007 IP
  5. MarkusJ_NZ

    MarkusJ_NZ Well-Known Member

    Messages:
    240
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Great, thanks; I have just tried the code on another server and it works... It actually looks to me that the global variable CURLOPT_FILE might not be declared. How can I get this "turned on" in PHP? I do C# as a day job so a PHP guru I'm not :(
     
    MarkusJ_NZ, Apr 9, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    I don't think that's the problem. Some servers have different default file/folder permissions, and therefore PHP cannot always create these files. Try chmodding the folder you're currently working in to 755.
     
    nico_swd, Apr 9, 2007 IP
  7. sanket

    sanket Active Member

    Messages:
    317
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    90
    #7
    Just give the 777 permission to same folder. it will work. it worked for me.
     
    sanket, Jun 25, 2008 IP
  8. sarausa

    sarausa Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I gave he permission of 777 but not working for me
     
    sarausa, Oct 21, 2010 IP
  9. rajeev_seo

    rajeev_seo Peon

    Messages:
    211
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    curl function use to extract data for xml or jason file there some argument passs problem
    for that error................
     
    rajeev_seo, Apr 23, 2011 IP
  10. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #10
    Try switch these two around & adding the return transfer option:

    
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_FILE, $fp);
    
    PHP:
     
    ThePHPMaster, Apr 24, 2011 IP