Does anyone know what this file error means ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

    Does anyone know what this file error means ?

    Hi,

    I am running ZipArchive on a downloaded zipped file
    and I am getting An Error No. 19.

    My log gives this output:

    -Saved as file: /home/guru54gt5/public_html/sys/a_xml_file.zip
    -File size: 278528 bytes
    Found: /home/guru54gt5/public_html/sys/a_xml_file.zip
    Could not open /home/guru54gt5/public_html/sys/a_xml_file.zip
    Error # 19
    This is the script I am running:

    Code:
    if (!class_exists('ZipArchive')) {
       write_log("Class ZipArchive not found\r\n");
         
       exit;
    } else {
        $zip = new ZipArchive;
    }
    
    if (!$file_zip) {
        write_log("Could not find  $file_zip\r\n Error # $err\r\n");  
        exit;
    		} 
    else {
        write_log("Found: $file_zip\r\n");
        }
    
    if (($err = $zip->open($file_zip)) !== true) {
        write_log("Could not open  $file_zip\r\n Error # $err\r\n");  
        exit;
    		} 
    else {
        write_log("File opened: $file_zip\r\n");
        }
    This ZipArchive is working fine in a similar script that donsloads a different
    file. Does anyone know what Error # 19 means and how
    I can cure it ?


    Thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    it means "Not a Zip Archive" (see Predefined Constants)

    Comment

    • jeddiki
      Contributor
      • Jan 2009
      • 290

      #3
      Thanks Dormilich.

      I looked up those "Predefined Constants" and I see a list of them.

      Above the list is this:
      The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

      ZipArchive uses class constants. There are three types of constants : Flags (prefixed with FL_), errors (prefixed with ER_) and mode (no prefix).
      But I can not see where you identify that the file is "Not a Zip Archive" .

      I manually unzipped the file to check it.

      Actually, none of my three download-unzip scripts worked last night,
      either I changed all three by mistake, or something in my php confiq has
      gone wrong.

      Would appreciate it if you can cast some more light on the problem

      Thanks


      .

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by jeddiki
        But I can not see where you identify that the file is "Not a Zip Archive" .
        the first user note/comment.

        Comment

        • jeddiki
          Contributor
          • Jan 2009
          • 290

          #5
          OK found it.

          (the notes were contracted and I didn't notice
          the + sign before)

          So I think there must be something wrong with my code
          because the file that download to my server is
          a zip file and I can unzip it manually. !

          I will do a few tests ( don't want to be lazy ;) )
          if I can not find the answer, then I will come back and
          post my code ... maybe you will see the error!

          Thanks again. :)



          .

          Comment

          • jeddiki
            Contributor
            • Jan 2009
            • 290

            #6
            Ok

            I have to admit defeat on this :(

            I did have it running OK up until Friday but something has changed.

            Maybe it is to do with the file name.

            I am downloading the clickbank marketplace
            and trying to unzip it using cUrl and ZipArchive.

            Here is my little script with all the logging.

            Code:
            $target_url = "http://www.clickbank.com/feeds/marketplace_feed_v1.xml.zip";
            $userAgent = 'EasyDL/3.xx';
            $file_zip = $file_dir."a_zip_clickbank.zip";
            $cef = "curl_err.txt"; 
            $ceh = fopen($cef, 'wb');
            
            write_log("Target_url: $target_url\r\n");
            
            // make the cURL request to $target_url
            $ch = curl_init();
            $fp = fopen("$file_zip", "wb");
            
            if ($fp === FALSE ) { 
              write_log("Problem opening $file_zip\r\n");
            	exit;
            }
            
            curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
            curl_setopt($ch, CURLOPT_URL,$target_url);
            curl_setopt($ch, CURLOPT_FAILONERROR, true);
            curl_setopt($ch, CURLOPT_STDERR, $ceh);		
            curl_setopt($ch, CURLOPT_VERBOSE, 1);
            curl_setopt($ch, CURLOPT_HEADER,0); 
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_AUTOREFERER, true);
            curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 10);
            curl_setopt($ch, CURLOPT_FILE, $fp);
            
            $output = curl_exec($ch);
            $info = curl_getinfo($ch);
            
            if ($output === FALSE || $info['http_code'] != 200) {
              write_log("No cURL data returned for $target_url [". $info['http_code']. "]\r\n ");
              if (curl_error($ch)) write_log($output."CURL error number: curl_errno($ch)\r\n CURL error: curl_error($ch)\r\n");
            	exit;
              }
            else {
              write_log("CURL completed successfully.\r\n");
            	}
            
            curl_close($ch);
            
            if(file_exists($file_zip)) {
              $fsz = filesize($file_zip);
              }
            else {
            	write_log("File: $file_zip does not exist \r\n");
            	  exit;
              }
            	
            write_log("Downloaded file: $target_url\r\n-Saved as file: $file_zip\r\n-File size: $fsz bytes \r\n");
            
            // Un zip the file 
            
            // After curl code:
            fclose($fp);
            fclose($ceh);
            
            if (!class_exists('ZipArchive')) {
               write_log("Class ZipArchive not found\r\n"); 
               exit;
            	 } 
            else {
              $zip = new ZipArchive;
            }
            
            if (!$file_zip) {
                write_log("Could not find  $file_zip\r\n Error # $err\r\n");  
                exit;
            		} 
            else {
                write_log("Found: $file_zip\r\n");
                }
            
            if (($err = $zip->open($file_zip)) !== true) {
                write_log("Could not open  $file_zip\r\n Error # $err\r\n");
                exit;
            		}
            else {
                write_log("File opened\r\n");
            }
            
            if (!$zip->extractTo($file_dir)) {
                write_log("Extraction error\r\n");
            		exit; 
                }
            This is my log that gets written by the scrpt.

            Target_url: http://www.clickbank.com/feeds/marke...eed_v1.xml.zip
            CURL completed successfully.
            Downloaded file: http://www.clickbank.com/feeds/marke...eed_v1.xml.zip
            -Saved as file: /home/guru54gt5/public_html/sys/a_zip_clickbank .zip
            -File size: 2764800 bytes
            Found: /home/guru54gt5/public_html/sys/a_zip_clickbank .zip
            Could not open /home/guru54gt5/public_html/sys/a_zip_clickbank .zip
            Error # 19
            The file a_zip_clickbank .zip shows up on my server
            and if I ftp it to my desktop, I can unzip it.

            I don't know why I amp getting the error, but I think i is something to do
            with defining the file name: $file_zip = $file_dir."a_zi p_clickbank.zip ";

            Any ideas where I have gone wrong ?

            Thanks.




            .

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              Originally posted by jeddiki
              Any ideas where I have gone wrong ?
              nope, it worked for me. $zip->open() returned true. (didn’t use cURL, though)

              PHP 5.3.1 on Darwin Melchior 9.8.0 Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009; root:xnu-1228.15.4~1/RELEASE_I386 i386

              Comment

              • jeddiki
                Contributor
                • Jan 2009
                • 290

                #8
                So what can be the problem then ?

                I really don't know what to try :(

                Maybe I am missing a SET_UP on the cUrl ?

                Comment

                • jeddiki
                  Contributor
                  • Jan 2009
                  • 290

                  #9
                  It MUST be something to do with me NOT using the
                  original file name - I seem to remember that when it was working
                  I was opening "marketplace_fe ed_v1.xml.zip"
                  not my "a_zip_clickban k.zip"

                  But I don't know how I coded it.

                  These two lines should mean that the file goes to
                  the specified output file right ?

                  Code:
                  curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
                  curl_setopt($ch, CURLOPT_FILE, $fp);
                  Hmm ....

                  nope , maybe I am confussing it with when I have succeeded in unzipping the
                  file, then I have to use what is unzipped namely: "marketplace_fe ed_v1.xml "

                  Oh my !


                  .

                  Comment

                  • jeddiki
                    Contributor
                    • Jan 2009
                    • 290

                    #10
                    Could this i statement be wrongly coded ?

                    Code:
                    if (($err = $zip->open($file_zip)) !== true) {
                        write_log("Could not open  $file_zip\r\n Error # $err\r\n");
                        exit;
                           }
                    else {
                        write_log("File opened\r\n");
                    }
                    Maybe I should use a simple:

                    Code:
                    if (!$zip->open($file_zip) ) {
                        write_log("Could not open  $file_zip\r\n Error # $err\r\n");
                        exit;
                           }
                    else {
                        write_log("File opened\r\n");
                    }
                    Could that be the problem ?


                    .

                    Comment

                    Working...