?
Solved

Using PHP to ftp a Zip file after creating it

Posted on 2005-04-22
7
Medium Priority
?
562 Views
Last Modified: 2008-11-18
The user opens the application on the browser and the system automatically goes to a predefined folder and uploads all the files in the folder without the user having to select the files. Next the application creates a zip file of all the files in the entire folder
Next this zip file is sent by ftp to an ftp server

I am trying to use the file upload withinn the dir object but so far has been unsuccessful. I dont have an idea on how I can create the zip file and then ftp it

With regards
Chaitali

The code is as follows -

<?php
      
      //Constant parameters defined
      $upload_dir = "../images/";
      $upload_url = "http://200.210.90.23";
      $mydir = dir('c:/images/');
      
      while(($file = $mydir->read()) !== false)
      {
          echo "Filename: $file<BR>";
            $file_path = $upload_dir.$file;
            move_uploaded_file($file, $file_path);
        
         }
   


?>

0
Comment
Question by:chaiti_c
  • 4
  • 3
7 Comments
 
LVL 7

Accepted Solution

by:
Promethyl earned 2000 total points
ID: 13842257

Here's the links to the free zip/unzip program.

http://www.info-zip.org/pub/infozip/UnZip.html
http://www.info-zip.org/pub/infozip/Zip.html


<?
$username = 'your_ftp_useername'; // your ftp username
$password = 'your_ftp_password';

shell_exec("zip myzip.zip myfiles.*");

$ftpr= ftp_connect('200.210.90.23');

ftp_login($ftpr, $username,$password);

ftp_put($ftpr, $uploadir, $mydir.'myzip.zip',FTP_BINARY);

ftp_close($ftpr);

?>
0
 
LVL 7

Expert Comment

by:Promethyl
ID: 13843575
Although this is largely untested code, I think the theory is sound.

Have you tried it? Does it work for your purposes?
0
 

Author Comment

by:chaiti_c
ID: 13848456
Hello
Thanks a lot.
I am trying it out. Please bear with me
I will be getting back as soon as possible
With regards
Chaitali
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:Promethyl
ID: 13848507
DOn't forget, if at first it can't transfer files, use ftp_pasv().
0
 

Author Comment

by:chaiti_c
ID: 13848770
Hello
Thanks for your help

Its working I am using pkzip to zip the file on my development server whose OS is Windows 2000. My production server's OS is Linux. Can you please suggest how i zip on the Linux server

Thanking you once again for your help
With regards
Chaitali
0
 
LVL 7

Expert Comment

by:Promethyl
ID: 13850318
This I know best !

Infozip should be on your box already.

The syntax is remarkably similiar to the infozip I gave you the link to. (Why do you think I recommended it? It's free unlike PKZIP dos.).  

Step one will be locating the unzip program on your *nix box.


-bash-2.05b$ which unzip
/usr/bin/unzip

So the program is in /usr/bin/unzip, eh?

"unzip data1" Would unzip all files to the current, however, in your case, I'd reccomend /usr/bin/unzip -o myzipfile.

UnZip 5.50 of 17 February 2002, by Info-ZIP.  Maintained by C. Spieler.  Send
bug reports to the authors at Zip-Bugs@lists.wku.edu; see README for details.

Usage: unzip [-Z] [-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]
  Default action is to extract files in list, except those in xlist, to exdir;
  file[.zip] may be a wildcard.  -Z => ZipInfo mode ("unzip -Z" for usage).

  -p  extract files to pipe, no messages     -l  list files (short format)
  -f  freshen existing files, create none    -t  test compressed archive data
  -u  update files, create if necessary      -z  display archive comment
  -x  exclude files that follow (in xlist)   -d  extract files into exdir

modifiers:                                   -q  quiet mode (-qq => quieter)
  -n  never overwrite existing files         -a  auto-convert any text files
  -o  overwrite files WITHOUT prompting      -aa treat ALL files as text
  -j  junk paths (do not make directories)   -v  be verbose/print version info
  -C  match filenames case-insensitively     -L  make (some) names lowercase
  -X  restore UID/GID info                   -V  retain VMS version numbers
                                             -M  pipe through "more" pager
Examples (see unzip.txt for more info):
  unzip data1 -x joe   => extract all files except joe from zipfile data1.zip
  unzip -p foo | more  => send contents of foo.zip via pipe into program more
  unzip -fo foo ReadMe => quietly replace existing ReadMe if archive file newer
-bash-2.05b$

If you dont' posses it, you can get it from http://www.info-zip.org/pub/infozip/.

Also, unix (Linux) variant is here:

http://www.mirrorservice.org/sites/ftp.info-zip.org/pub/infozip/UNIX/LINUX/

Pretty simple install. Precompiled binaries are available if you know which you need, glibc or libc5.

0
 

Author Comment

by:chaiti_c
ID: 13856545
Thanks one again I am going to try it out. This application would not have been possible ithout your help
With regards
Chaitali
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question