Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
  1. #1
    Senior Member
    Join Date
    Aug 2011
    Posts
    190
    Member #
    29153
    Liked
    2 times

    Copying files without a ftp cliant

    How can I write a php file to download an entire folder onto my computer from my website?


  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,291
    Member #
    5580
    Liked
    665 times
    I tested the script below and it works.

    I put the script in my main directory and the folder I wanted to zip was a directory called "images",

    It then takes all files and subfolders in "images", zips them, and serves it to me (through the open or save dialog window), with a download called "archived.zip".


    You will need to have a webhost with a UNIX server and the ziparchive library, which most webhosts have installed.


    PHP Code:
    <?php
    $the_folder 
    'images';
    $zip_file_name 'archived.zip';

    class 
    FlxZipArchive extends ZipArchive {
            
    /** Add a Dir with Files and Subdirs to the archive;;;;; @param string $location Real Location;;;;  @param string $name Name in Archive;;; @author Nicolas Heimann;;;; @access private  **/
        
    public function addDir($location$name) {
            
    $this->addEmptyDir($name);
             
    $this->addDirDo($location$name);
         } 
    // EO addDir;
            /**  Add Files & Dirs to archive;;;; @param string $location Real Location;  @param string $name Name in Archive;;;;;; @author Nicolas Heimann * @access private   **/
        
    private function addDirDo($location$name) {
            
    $name .= '/';         $location .= '/';
          
    // Read all Files in Dir
            
    $dir opendir ($location);
            while (
    $file readdir($dir))    {
                if (
    $file == '.' || $file == '..') continue;
              
    // Rekursiv, If dir: FlxZipArchive::addDir(), else ::File();
                
    $do = (filetype$location $file) == 'dir') ? 'addDir' 'addFile';
                
    $this->$do($location $file$name $file);
            }
        } 
    }
    $za = new FlxZipArchive;
    $res $za->open($zip_file_nameZipArchive::CREATE);
    if(
    $res === TRUE)    {
        
    $za->addDir($the_folderbasename($the_folder)); $za->close();
    }
    //  Serve the zipped file to the user ....
       
    header('Content-Type: application/zip');
        
    header("Content-Disposition: attachment; filename = $zip_file_name");
        
    header('Content-Length: ' filesize($zip_file_name));
        
    header("Location: $zip_file_name");
     
    ?>

    EDIT:
    Serving one zipped file is the best way to do this. It's efficient, and you can call it anything you want, which makes it easier to archive them as backups.
    Last edited by mlseim; Oct 18th, 2016 at 03:31 PM.


  4. #3
    Senior Member
    Join Date
    Aug 2011
    Posts
    190
    Member #
    29153
    Liked
    2 times
    I did that and got a file with this name: archived.zip.w9ynKs

    I assumed I had to download it and rename it without the .w9ynKs but when I did, it tells me that Windows cannot open the folder.

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,291
    Member #
    5580
    Liked
    665 times
    hmmm.... not sure what "w9ynKs" means.
    Try changing the name "archive.zip" to something else like "myfiles.zip" .. change it in the script before you run it.
    Maybe "archive.zip" is related to something else.


  6. #5
    Senior Member
    Join Date
    Aug 2011
    Posts
    190
    Member #
    29153
    Liked
    2 times
    Same thing

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,291
    Member #
    5580
    Liked
    665 times
    Not sure what to say. I've never seen that before.
    Who is your webhost?


  8. #7
    Senior Member
    Join Date
    Aug 2011
    Posts
    190
    Member #
    29153
    Liked
    2 times
    It is Godaddy

  9. #8
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,291
    Member #
    5580
    Liked
    665 times
    Take a look at this:
    https://www.godaddy.com/community/Bu...m-p/7944#M2459

    Not sure if that's anything, but check it out.


  10. #9
    Senior Member
    Join Date
    Aug 2011
    Posts
    190
    Member #
    29153
    Liked
    2 times
    I would need it to work similar to how pinterest copies images from one site to theirs. Except I need to move mp3 files.

  11. #10
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,291
    Member #
    5580
    Liked
    665 times
    When someone recommends a website, or references it, yes, Pinterest grabs a screenshot or finds an image withing the HTML that they can use to display on their site. I'm not sure if they actually "steal" the image and put it on their server. I would think they only save the source path to the image.

    It sounds like you want to find an mp3 file (look for the HTML source path), then use PHP to actually open and copy it to your website?

    Download File from Remote Server with PHP CURL

    Not sure how ethical this is ... without permission from the site owner at least. They should not have any mp3 files on their server unless they adhere to copyright laws. I guess you would be in the same boat. I'm not here to judge, I'm just saying what I'm thinking.



Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:42 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com