Advertisement

09.21.2007 at 10:12PM PDT, ID: 22845805
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.3

Going from Zip to GZIP?

Asked by webseth in PHP Scripting Language, PHP and Databases

Ok, my hosting company tells me that they do not support zip functions, and I will have to use gzip to extract files from a .zip

Can the following script be changed to do this? I have no idea how to use gzip!

<?
     define ( 'LOG_FILE', 'log.txt' ); // log file that records the complete process
     define ( 'FTP_USER', xxxx' ); // ftp login username
     define ( 'FTP_PASS', 'xxxx' ); // ftp login password
     define ( 'FTP_HOST', 'xxxx' ); // ftp server name
     define ( 'SAVE_PATH', '/xxxx/' ); // inlude the trailing '/'


     $get_file = 'DailyData_CATisRES.zip'; // path and name of file on the FTP server (download file)
     $new_file = SAVE_PATH . 'DailyData_CATisRES.zip'; // the local temp zip file name and path... (save file)
     // end configure

  $files = array ();

     log_file ( 'SCRIPT (START): New database dump process started', 1 );

     $io = ftp_connect ( FTP_HOST ) or log_file ( 'FTP CONNECT: connection error, ' . FTP_HOST, 0 );

     log_file ( 'FTP (CONNECT): connection to ' . FTP_HOST . ' returned true', 1 );

     if ( ( $lu = @ftp_login ( $io, FTP_USER, FTP_PASS ) ) !== false )
     {
          log_file ( 'FTP (LOGIN): login to ' . FTP_HOST . ' returned true', 1 );

          $lf = fopen ( $new_file, 'wb' ) or log_file ( 'FILE ERROR: can not create temp file, ' . $new_file, 0 );

              ftp_pasv($io, true) or log_file ( 'FTP PASV: Unable to set passive mode.', 0 );

          if ( ftp_fget ( $io, $lf, $get_file, FTP_BINARY, 0 ) !== false )
          {
               log_file ( 'FTP (GET): get download file ' . $get_file . ' returned true', 1 );

               fclose ( $lf );

               log_file ( 'FILE (SAVE): saved down load file ' . $get_file . ' to ' . $new_file, 1 );

               $zf = zip_open ( $new_file ) or log_file ( 'FILE ERROR: can not open to unzip, ' . $new_file, 0 );

               if ( $zf )
               {
                    while ( $zs = zip_read ( $zf ) )
                    {
                         if ( zip_entry_open ( $zf, $zs, 'rb' ) !== false )
                         {
                              $zo = zip_entry_read ( $zs, zip_entry_filesize ( $zs ) );
                              $fn = zip_entry_name ( $zs );

                              $fs = fopen ( SAVE_PATH . $fn, 'wb' );
                              fputs ( $fs, $zo );
                              fclose ( $fs );

                              $files[$fn] = SAVE_PATH . $fn;
                         }
                    }

                    zip_close ( $zf );

                    log_file ( 'FILE (UNZIP): process download file, ' . $new_file . ' returned true', 1 );

                    unlink ( $new_file );

               }
               else
               {
                    log_file ( 'FILE ERROR: can not open or read ' . $new_file . ' (check permissions)', 0 );
               }

          }
          else
          {
               log_file ( 'FILE ERROR: can not download ' . $get_file . ' from ' . FTP_HOST . ' (check path)', 0 );
          }

          ftp_close ( $io );

     }
     else
     {
          log_file ( 'FTP ERROR: user not allowed access on ' . FTP_HOST, 0 );
     }

     log_file ( 'SCRIPT (END): New database dump process finished, exiting...', 2 );
       print "Scipt Seemed to Have Work";


     function log_file ( $data, $type )
     {
          $time = date ( 'r', time () );

          $fo = fopen ( LOG_FILE, 'a' );
          fputs ( $fo, $time . ', ' . $data . "\r\n" );

          if ( $type == 2 )
          {
               fputs ( $fo, str_repeat ( '-', 72 ) . "\r\n\r\n" );
          }

          fclose ( $fo );

          if ( $type == 1 )
          {
               return;
          }

          exit ();
     }
?>
Start Free Trial
 
Loading Advertisement...
 
[+][-]09.22.2007 at 02:50PM PDT, ID: 19942739

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, PHP and Databases
Sign Up Now!
Solution Provided By: tbboyett
Participating Experts: 2
Solution Grade: A
 
 
[+][-]09.24.2007 at 12:38PM PDT, ID: 19951113

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 14-day free trial to view this Assisted Solution or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_1_20070628