Jump to content

Php permission


cotede2

Recommended Posts

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.