Jump to content

how to extract

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
5 replies to this topic

#1
safairon

safairon

    Newbie

  • Members
  • Pip
  • 3 posts
Hi to all
I want to extract a zip archive file in server.
In my local system the code is running and working OK.
But in my host in internet the code was not working OK.
The problem raise because the directory was make in server dos not have full access (777).
Main directory create OK. But sub directory and file in main directory dos not create OK
my code is
(Note : I us pclzip.lib.php function archive):

<?php
	include('pclzip.lib.php');
	//zip file to extract
	
	$archive = new PclZip('sef.zip');
	//extract to a folder called newdir
	echo "safa<br>";
	
	if ($archive->extract() == 0) 
	{
		//failed
		die("Error : ".$archive->errorInfo(true));
	}
	echo "Successfully extracted files";
?>

Edited by Jaan, 30 January 2010 - 04:33 AM.
Please use code tags when you are posting your codes!


#2
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
I would recommend using the built in PHP ZipArchive class over some third party lib.

You can try chmoding the directory yourself.

#3
safairon

safairon

    Newbie

  • Members
  • Pip
  • 3 posts
Hi and thank you because of your reply

I use PHP ZipArchive class and see the same problem
And about the CHMode. In extract Zip Archive file, if the zip file contain sub directories, we do not set CHmode manually because in extracting we need automatic CHMode

thank you.

#4
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
You can use the system() function to CHMode the sub directories.

#5
Feral

Feral

    Programmer

  • Members
  • PipPipPipPip
  • 162 posts
You can read the file structure inside the zip archive and create the folders in advance using mkdir which takes the chmod setting as a parameter. Then iterate through the archive and extract the files.

Personally I treat archives as a normal file upload. I create an array that contains all the information about the archive with each folder representing a new inner array.

e.g

array(
"folder name" => array('filename1', filename2'),
"folder name" => array('filename1', filename2', filename3'));


Then I extract all the files to a temp directory without preserving the file system. After that I create the directory structure and move the files into place. At the end I delete all the files from the temp folder.

note: this is a much simplified version of what actually needs to be done. this does not take into account the possibility that there might be 2 or more files in the archive that have the same name.

#6
safairon

safairon

    Newbie

  • Members
  • Pip
  • 3 posts
Hello all and thank you for your replies.
I found the problem.
With mkdire() function (function in PHP archive) we make the directories.
In the pclzip.lib.php I found this line
if (mkdir($p_dir, 0777))
that make directory in extracting steps.
But in practice the directories was make in 0755 permission.

To solve this problem I try to do it in ftp mode (I try to create directories in ftp function) but ftp functions do not work ok.
This is my code for creating directory with ftp functions:

<?php

$ftp_server = "ftp.my-domain.com";
$ftp_user = "user-name";
$ftp_pass = "password";
$dir = "example";

// set up a connection or die
$conn_id = ftp_connect($ftp_server , 21) or die("Couldn't connect to $ftp_server");

// try to login
if (@ftp_login($conn_id, $ftp_user, $ftp_pass)) {
echo "Connected as $ftp_user@$ftp_server\n<br>";
} else {
echo "Couldn't connect as $ftp_user\n<br>";
}

// try to create the directory $dir
if (ftp_mkdir($conn_id ,$dir) === true) {
echo "successfully created $dir\n";
} else {
echo "There was a problem while creating $dir\n";
}

// close the connection
ftp_close($conn_id);
?>

then i recived the message:

Connected as rayaecom-at-ftp.my-domain-dot-com
There was a problem while creating example