cotede2 Posted July 9, 2009 Share Posted July 9, 2009 http://seabova.com/zip.php /home/content/s/e/a/seabova/html/idxphotos.zip Warning: fopen(/538368a.jpg) [function.fopen]: failed to open stream: Permission denied in /home/content/s/e/a/seabova/html/zip.php on line 34 Hello , I 'd like from a php script to be able to unzip to extract an archive. This is the script : <?php function mkdir_recursif($dir) { $parties = preg_split('#/' . preg_quote(DIRECTORY_SEPARATOR) . '#', $dir, -1, PREG_SPLIT_NO_EMPTY); $base = ''; foreach ($parties as $p) { if (!file_exists($base . $p)) { mkdir($base . $p); } $base .= $p . DIRECTORY_SEPARATOR; } } function extractTo($archive, $destination, $ecrase = FALSE, $fichiers = NULL) { if (($zip = zip_open($archive)) === FALSE) { die(var_dump($zip)); return FALSE; } if (!file_exists($destination)) { mkdir_recursif($destination); } while ($entree = zip_read($zip)) { $fichier = zip_entry_name($entree); if (is_array($fichiers) && !in_array($fichier, $fichiers)) { continue; } if (zip_entry_open($zip, $entree)) { $contenu = zip_entry_read($entree, zip_entry_filesize($entree)); zip_entry_close($entree); if ($ecrase !file_exists($destination . DIRECTORY_SEPARATOR . $fichier)) { if (strpos($fichier, '/') !== FALSE) { mkdir_recursif($destination . DIRECTORY_SEPARATOR . dirname($fichier)); } $fp = fopen($destination . DIRECTORY_SEPARATOR . $fichier, 'w'); fwrite($fp, $contenu); fclose($fp); } } else { zip_close($zip); return FALSE; } } zip_close($zip); return TRUE; } $path = '/home/content/s/e/a/seabova/html/idxphotos.zip'; echo $path; # Exemples d'utilisation # Extraction de l'ensemble des fichiers qui composent l'archive extractTo( $path, ''); /* $path = '/home/content/s/e/a/seabova/html/idxfullphotos.zip'; extractTo( $path, ''); */ ?> On my localhost, it works well (windows XP + easyphp) but not on my host. zip.php is chmoded 777 as are also the folders idxphotos and idxfullphotos so I don't get it. thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/165356-php-permission/ Share on other sites More sharing options...
wildteen88 Posted July 9, 2009 Share Posted July 9, 2009 As you are not providing a destination for where the files get extracted to. PHP is trying to extract file in the root of the file system ( this is what / means at the beginning fo file paths). It is not possible to create files in the root of the file system with PHP. In order to prevent this change this function extractTo($archive, $destination, $ecrase = FALSE, $fichiers = NULL) { To function extractTo($archive, $destination, $ecrase = FALSE, $fichiers = NULL) { $destination = $_SERVER['DOCUMENT_ROOT'] .'/'. $destination;[code=php:0] Now if no destination is provided your script will extract the files to your sites document root Quote Link to comment https://forums.phpfreaks.com/topic/165356-php-permission/#findComment-872140 Share on other sites More sharing options...
cotede2 Posted July 9, 2009 Author Share Posted July 9, 2009 As you are not providing a destination for where the files get extracted to. PHP is trying to extract file in the root of the file system ( this is what / means at the beginning fo file paths). It is not possible to create files in the root of the file system with PHP. In order to prevent this change this function extractTo($archive, $destination, $ecrase = FALSE, $fichiers = NULL) { To function extractTo($archive, $destination, $ecrase = FALSE, $fichiers = NULL) { $destination = $_SERVER['DOCUMENT_ROOT'] .'/'. $destination;[code=php:0] Now if no destination is provided your script will extract the files to your sites document root thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/165356-php-permission/#findComment-872223 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.