Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    What is this file handling error ?

    Hi,
    I am trying to download a file and unzip it
    but I get this error

    Could not open /home/guru54gt5/public_html/sys/clickbank.zip
    Error # 11


    I keep a log which opens at the start
    of the code (not shown).

    This is my code:

    PHP Code:
    $target_url "http://www.clickbank.com/feeds/marketplace_feed_v1.xml.zip";
    $userAgent 'EasyDL/3.xx';

    $file_zip "clickbank.zip";


    $cef "curl_err.txt"
    $ceh fopen($cef'w');

    // write to log
    $content "Target_url: $target_url\r\n";
    fwrite($handle$content);  

    // make the cURL request to $target_url
    $ch curl_init();
    $fp fopen("$file_zip""wb"); 
    curl_setopt($chCURLOPT_USERAGENT$userAgent);
    curl_setopt($chCURLOPT_URL,$target_url);
    curl_setopt($chCURLOPT_FAILONERRORtrue);
    curl_setopt($chCURLOPT_STDERR$ceh);        
    curl_setopt($chCURLOPT_VERBOSE1);
    curl_setopt($chCURLOPT_HEADER,0); 
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
    curl_setopt($chCURLOPT_AUTOREFERERtrue);
    curl_setopt($chCURLOPT_BINARYTRANSFER,true);
    curl_setopt($chCURLOPT_TIMEOUT10);
    curl_setopt($chCURLOPT_FILE$fp);

    $page curl_exec($ch);


    if (!
    $page) {
      
    $content "CURL error number: curl_errno($ch)\r\n CURL error: curl_error($ch)\r\n";
      
    fwrite($handle$content);  
        exit;
    }

    curl_close($ch);

    $fsz filesize($file_zip);

    $content "Downloaded file: $target_url\r\n Saved as file: $file_zip\r\n  File size: $fsz bytes \r\n";
    fwrite($handle$content);  

    // Un zip the file 

    // After curl code:
    fclose($fp);
    fclose($ceh);

    $file_zip '/home/guru54gt5/public_html/sys/'.$file_zip;

    if (!
    class_exists('ZipArchive')) {
       
    $content "Class ZipArchive not found\r\n";
       
    fwrite($handle$content);  
       exit;
    } else {
        
    $zip = new ZipArchive;
    }

    if ((
    $err $zip->open($file_zip)) !== true) {
        
    $content "Could not open  $file_zip\r\n Error # $err\r\n";
        
    fwrite($handle$content);  
        exit;
    } else {
        
    $content "File opened\r\n";
        
    fwrite($handle$content);  
    }

    if (!
    $zip->extractTo($file_dir)) {
        
    $content "Extraction error\r\n";
        
    fwrite($handle$content);  
        }

    $zipSS $zip->getStatusString();        
    $content "StatusString: $zipSS\r\n";
    fwrite($handle$content);  

    if (!
    $zip->close()) {
        
    $content "Error on close\r\n";
        
    fwrite($handle$content);  
    } else {
        
    $content "Unzipped file to: $file_dir\r\n";
        
    fwrite($handle$content);



    $file $file_dir.'clickbank.xml';

    exit; 
    My log file shows this:


    Notice that the filesize() doesn't appear to work - probably no file ?

    New record - Time Stamp: 11:06:33 Tuesday, 26 January 2010
    This script: sys/auto_cb_update.php, This file: /home/guru54gt5/public_html/sys/a_log_cb_update.txt
    Target_url: http://www.clickbank.com/feeds/marke...eed_v1.xml.zip
    Downloaded file: http://www.clickbank.com/feeds/marke...eed_v1.xml.zip
    Saved as file: clickbank.zip
    File size: filesize(clickbank.zip) bytes
    Could not open /home/guru54gt5/public_html/sys/clickbank.zip
    Error # 11
    And the error file (curl_err.txt) shows:

    Code:
    * About to connect() to www.clickbank.com port 80
    *   Trying 74.63.153.33... * connected
    * Connected to www.clickbank.com (74.63.153.33) port 80
    > GET /feeds/marketplace_feed_v1.xml.zip HTTP/1.1
    User-Agent: EasyDL/3.xx
    Host: www.clickbank.com
    Accept: */*
    
    < HTTP/1.1 200 OK
    < Date: Tue, 26 Jan 2010 18:34:58 GMT
    < Server: Apache
    < ETag: W/"2325066-1264507973000"
    < Last-Modified: Tue, 26 Jan 2010 12:12:53 GMT
    < Content-Length: 2325066
    < Content-Type: application/zip
    * Connection #0 to host www.clickbank.com left intact
    * Closing connection #0
    So does this mean that it did not download the zip file ?

    If if didn't - what could be the problem ?

    If you can see any obvious erros in my
    code, I would appreciate any advice,
    thanks.



    .
    Last edited by jeddi; 01-26-2010 at 06:44 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #2
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,251
    Thanks
    12
    Thanked 340 Times in 336 Posts
    from first glance I’d say the file is not where you expect it to be.

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Maybe different than a location error. See the manual page. One of the comments lists these return values:
    ZIPARCHIVE::ER_EXISTS - 10
    ZIPARCHIVE::ER_INCONS - 21
    ZIPARCHIVE::ER_INVAL - 18
    ZIPARCHIVE::ER_MEMORY - 14
    ZIPARCHIVE::ER_NOENT - 9
    ZIPARCHIVE::ER_NOZIP - 19
    ZIPARCHIVE::ER_OPEN - 11
    ZIPARCHIVE::ER_READ - 5
    ZIPARCHIVE::ER_SEEK - 4
    Which doesn't really seem very helpful, but maybe it'll offer some direction.
    Are you a Help Vampire?

  • #4
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for your reply.

    So you think it is a problem with the unzipping ?

    It seems to me that there is a problem with the download
    of the zip file.

    I slightly changed the script
    - I have added a couple of lines to check
    if the zip file exists:

    PHP Code:
    if(file_exists($file_dir.$file_zip)) {
      
    $fsz filesize($file_dir.$file_zip);
      }
    else {
        
    $fsz "No file";
        }
        
    $content "Downloaded file: $target_url\r\n Saved as file: $file_zip\r\n  File size: $fsz bytes \r\n";
    fwrite($handle$content); 
    The output from this in my log file is:

    This script: sys/auto_cb_update.php, This file: /home/guru54gt5/public_html/sys/a_log_cb_update.txt
    Target_url: http://www.clickbank.com/feeds/marke...eed_v1.xml.zip
    Downloaded file: http://www.clickbank.com/feeds/marke...eed_v1.xml.zip
    Saved as file: clickbank.zip
    File size: No file bytes
    Could not open /home/guru54gt5/public_html/sys/clickbank.zip
    Error # 11
    I think File size: No file bytes shows that
    there is no file ?

    What of the curl error file ?
    Does it imply that the download was OK ?

    But, then if there was any download error
    shouldn't I get an error code from this line: if (!$page) { ?



    .
    Last edited by jeddi; 01-26-2010 at 07:58 PM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #5
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    That certainly seems to imply that the file doesn't exist. Maybe you should test the result of the fopen for $fp (at the top of the curl_opts). You may also want to look at testing the response code (for 200/success). I noticed that possibility in the comments for curl_exec.
    Are you a Help Vampire?

  • #6
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Not quite sure what you mean by:

    test the result of the fopen for $fp
    and how do I do this ?

    look at testing the response code (for 200/success).
    Thanks
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #7
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I meant to test the return value from fopen. It return FALSE on error.

    For testing the response code, check out this comment for a start. I think there were others there, too.
    Are you a Help Vampire?

  • #8
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks for your suggestions and the link.

    I have now added some more tests:

    PHP Code:
    if ($fp === FALSE ) { 
      
    $content "Problem opening $file_zip\r\n";
      
    fwrite($handle$content);  
        exit;

    and
    PHP Code:
    $output curl_exec($ch);
    $info curl_getinfo($ch);

    if (
    $output === false || $info['http_code'] != 200) {
      
    $content "No CURL data returned for $target_url ["$info['http_code']. "]\r\n ";
      if (
    curl_error($ch))
        
    $content $output."CURL error number: curl_errno($ch)\r\n CURL error: curl_error($ch)\r\n";
       
    fwrite($handle$content);  
       exit;
      }
    else {
        
    $content "CURL completed successfully.\r\n";
        
    fwrite($handle$content);
        } 
    Hopefully that should help.

    ( Do you see anything wrong there ? )


    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #9
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Hmm .. I am still getting a file open error...


    PHP Code:

    OPEN  the log file code here )

    $file_zip "clickbank.zip";


    $cef "curl_err.txt"
    $ceh fopen($cef'w');

    $content "Target_url: $target_url\r\n";
    fwrite($handle$content);  

    // make the cURL request to $target_url
    $ch curl_init();
    $fp fopen($file_zip"wb");

    if (
    $fp === FALSE ) { 
      
    $content "Problem opening $file_zip\r\n";
      
    fwrite($handle$content);  
        exit;

    I get the "Problem opening clickbank.zip"
    in my log file.

    Now why would that happen ?

    I even tried deleting the file with unlink first as well
    by placing this at the top of the script:

    PHP Code:
    if(file_exists($file_dir.'clickbank.zip'))  unlink($file_dir.'clickbank.zip'); 
    But I still get the same error !

    According t the Manual: fopen("filename", "w");
    Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it.
    So if the file exists or not, it should be OK


    Is this line:
    if ($fp === FALSE ) {
    the correct thing to do ?


    BTW
    I also tried: $fp = fopen($file_zip, "wb"); // took quotes off
    but no difference


    .
    Last edited by jeddi; 01-27-2010 at 07:41 AM.
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #10
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I think you're testing the fopen result correctly. Is your PHP in safe mode? There's a note on the fopen page:
    Note: When safe mode is enabled, PHP checks whether the directory in which the script is operating has the same UID (owner) as the script that is being executed.
    Does the web server user have write access to the directory? Besides a simple look-see, you can also test this with is_writable.
    Are you a Help Vampire?

  • #11
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Thanks Tom,
    I appreciate your help (as always).

    When I added the full path to the file name, the problem
    went away. It is still a bit weird because I did not do that before and
    it worked. Any way, it works norks now

    BTW
    do you know ...

    is if($fp === FALSE ) a valid test ?

    and is it the same as if(!$fp) ?




    .
    If you want to attract and keep more clients, then offer great customer support.

    Support-Focus.com. automates the process and gives you a trust seal to place on your website.
    I recommend that you at least take the 30 day free trial.

  • #12
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    Since the fopen return value is either a file pointer or false, then if ($fp === FALSE) is a good test. The second would work, too.

    It's good practice to test for an exact value (FALSE, in this case) if you know what will be returned, so I'd use the first one. There are some functions besides fopen where just testing the NOT would yield inconsistent results because of all of the values that are equivalent in loose-typing (0, '', etc.). That's the reason it's good practice - when you get in the habit of testing exact return values where applicable, you can save a few headaches.
    Are you a Help Vampire?


  •  

    Posting Permissions

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