DBZgoku Posted January 26, 2010 Share Posted January 26, 2010 Hi i'm new to phpfreaks and i need some help on zipping a folder! i work on a project under windows, using Wamp. i use the function posted underneath and it works, but, when i unzip the zip file, in it it contains the whole path i.e. C:\wamp\www\uploads\Csc290\(+ the files). Can anyone guide me how to get only a folder with Csc290 and the files included in it? any help or tips will be appreciated! thnx i get the names of the folders through the database and use them as input to the function if($instr== "false"){ // Set path to download zip file $dld = $row['asgnname'].".zip"; $dlddir = "./uploads/".$row2['coursename']."/".$row['asgnname']."/"; $dldlink = "./uploads/".$row2['coursename']."/".$row['asgnname'].".zip"; }else{ $dld = "instructions-".$row['asgnname'].".zip"; $dlddir = './uploads/'.$row2['coursename'].'/'.$row['asgnname'].'/instructions/'; $dldlink="./uploads/".$row2['coursename']."/instructions-".$row['asgnname'].".zip"; } function Zip($source, $destination) { if (extension_loaded('zip') === true) { if (file_exists($source) === true) { $zip = new ZipArchive(); if ($zip->open($destination, ZIPARCHIVE::CREATE) === true) { $source = realpath($source); if (is_dir($source) === true) { $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); foreach ($files as $file) { $file = realpath($file); if (is_dir($file) === true) { $zip->addEmptyDir(str_replace($source . '/', '', $file . '/')); } else if (is_file($file) === true) { $zip->addFromString(str_replace($source . '/', '', $file), file_get_contents($file)); } } } else if (is_file($source) === true) { $zip->addFromString(basename($source), file_get_contents($source)); } } return $zip->close(); } } return false; } zip($dlddir,$dldlink); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.