Jump to content

Download empty folder subfolder structure maybe as a zip file


jimjiminyjimjim

Recommended Posts

I'm creating a job sheet web app. I would like an empty folder and subfolder structure to be created automatically and then downloaded to the desktop - then users will drag files into these folders before saving them to a local server - only because we can't upload very large artwork files to our webserver.

 

I can get PHP to create the folders and subfolders using mkdir.

 

But now I want to serve them automatically from the jobsheet app as a download to desktop. The only way I think this is possible is by zipping up the folders using this:

 


<?PHP
// increase script timeout value
ini_set('max_execution_time', 300);

// create object
$zip = new ZipArchive();

// open archive 
if ($zip->open('my-archive.zip', ZIPARCHIVE::CREATE) !== TRUE) {
    die ("Could not open archive");
}

// initialize an iterator
// pass it the directory to be processed
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("app/"));

// iterate over the directory
// add each file found to the archive
foreach ($iterator as $key=>$value) {
    $zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");        
}

// close and save archive
$zip->close();
echo "Archive created successfully.";    
?> 

 

 

However, it doesn't seem to be working - is this because the folders and subfolders are all empty?

 

Or it could be because the PHP is pointing to the wrong folder? Can anyone explain the relationship between the location this PHP script is saved and the app folder that the "app/" address the script currently points to. They currently resides in the same root folder.

 

Short of that I'm stumped!!  :-\

Thanks for the suggestion - its still doesn't seem to be working?

 

I've read all sorts on the forums about zipfiles and php but nothing seems to work as I need. I can get files to zip and I can get folders to zip but not extract correctly - I'm a bit stuck.

 

Whats the simplest way to zip up a folder and its subfolders given that they are all empty, and then download it automatically.

 

Any help much appreciated.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.