PharData extractTo method failed to extract .tar.gz on linux environment - php

I would like to extract .tar.gz file into the particular folder. I have used cURL to download the .tar.gz file from MailChimp batch operation. I have used below code to extract tar file.
$phar = new \PharData('upload/test.tar.gz');
$phar->extractTo('upload/',null, true);
It is working on windows environment. But on Linux(Ubuntu), I got below error when to run above code.
Uncaught exception 'PharException' with message 'Extraction from phar "upload/test.tar" failed: Cannot extract ".", internal error'
I have already set default apache user and group permission for upload folder.
sudo chown -R www-data:www-data upload/
PHP Version: 5.6.24
I have attach sample .tar.gz file: http://www.simbanic.com/_projects/test/05c902076e.tar.gz

I had the same problem with MailChimp batch response archive.
Stupid solution, but it works...
$p = new PharData($tarGzArchive, RecursiveDirectoryIterator::SKIP_DOTS);
$p->convertToData(Phar::ZIP);
$zip = new ZipArchive;
$res = $zip->open($createdZipArchive);
if ($res === TRUE) {
$zip->extractTo($destinationPath);
$zip->close();
}

Related

ZipArchive does not work in laravel

I have laravel project and whant to add feature for ziping files. I am using php ZipArchive. When I'm trying to create ZIP file using just PHP, I have luck, but when I'm trying with Laravel, zip files does not been created.
So I have add: use ZipArchive;
And just doing:
$file_path = storage_path("creatives/helloworld.zip");
$zip = new ZipArchive();
$zip->open($file_path, ZipArchive::CREATE);
But there is not error and no zip file. What can you advise me?
It is very late to reply but this may help someone. I too had this same issue but then I opted for using "Process Component" and execute the command to create zip.
If you are only concerned with the zip creation. You can use the following code.
<?php
$projectFolder = $destinationPath;
$zipFile = $nameOftheFile;
$process = new Process("zip -r $zipFile $projectFolder");
$process->run();
// executes after the command finishes
if (!$process->isSuccessful()) {
// throw new ProcessFailedException($process);
$response['msg'] = $process->getOutput();
}else{
$response['msg'] = 'Build zipped';
}
return $response;
Don't forget to install zip extension. Use the below command.
sudo apt-get install zip

throw new FileException('File must be readable.');

I'm using Laravel , The following code works on my local machine (Mac)
$Avatarpath = base_path()."/uploads/image/avatar.png"
$filePath = base_path()."/uploads/image/myimage.png" //which gives "/var/www/myproject/uploads/image/myimage.png"
return Response::download(file_exists($filepath) ? $filepath :$Avatarpath);
but when I deploy the same code on linux (Centos) server , it throws the following Exception
throw new FileException('File must be readable.');
Additional info: "uploads" folder has drwxr-xr-x (775) permissions
Thank you your interest to fix this issue.
Important is that the permissions for the file itself are correct too!
Usually in this cases you should run chmod with the recursive flag (-R):
chmod -R 775 uploads/
This Exception is thrown if function http://php.net/manual/en/splfileinfo.isreadable.php is returning false.
Your file permissions must be denying the file read.

Server migration troubles with Imagick, Fopen, PHP and Permissions

I've recently migrated linux servers.
I'm currently getting this error when trying to upload an image using Imagick from a form.
Warning: fopen(/home/user/public/website.com/public/images/users/current/thumb/username.jpg): failed to open stream: Permission denied in /home/user/public/website.com/public/inc/functions/functions.php on line 864
The code that is run resides in a function:
try{
$im = new Imagick($image['tmp_name']);
if($im_w != 'O' && $im_h != 'O'){
$im->cropThumbnailImage($im_w,$im_h);
}
$fp = fopen($path, 'w'); //the line that is causing the error to occur. line 864.
$im->writeImageFile($fp);
return 1;
}
catch(Exception $e)
{
echo $e->getMessage();
}
I've had a look through various PHP/Linux fixes for permissions, The /images/ directory and subdirectories currently have permission: 755
Can anyone help me with a solution. Comment if you need to know anything else.
Thanks in advance.
Simply entered the command into my linux command line:
sudo chmod -R 777 /home/username/public/website.com/public/x_images/

Mac OS X permissions to create a zip file

After searching the internet find an answer I've decided to ask for help directly.
I am running mac os x 10.7, PHP, Apache and MySQL. I am trying to let a user select files from a form have them zipped and sent to the individual. At first PHP couldn't even create a file. I found the following:
sudo chmod -R +a "_www allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directory_inherit" ~/Sites
Which allowed me to create a file. But when I try to create a zip I get some unknown extension being appended at the end and 2 files are being created. So not knowing what was wrong I thought I would just find the file by opening the directory and forcibly renaming it back to *.zip. I have checked the file after renaming manually and it seems to be fine.
I get the following error:
Warning: rename(tmp/RosenData082112-1102.zip.ohoKRw,RosenData082112-1102.zip) [function.rename]: Permission denied in /Users/mmcri/Sites/rosenlab/download.php on line 42
ls -le reveals this to the files:
-rw-------+ 1 _www staff 43775 Aug 21 11:02 RosenData082112-1102.zip.1qJUE4
0: user:_www inherited allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity
-rw-------+ 1 _www staff 43775 Aug 21 11:02 RosenData082112-1102.zip.ohoKRw
0: user:_www inherited allow read,write,append,readattr,writeattr,readextattr,writeextattr,readsecurity
Here is the PHP code section making the zip file:
if(extension_loaded('zip'))
{
$zip = new ZipArchive();
$zipname = "RosenData".date("mdy-Hi").".zip";
if($zip->open($direct.$zipname, ZIPARCHIVE::CREATE) === TRUE)
{
foreach($filelist as $file)
$zip->addFile($path.$file,$file) or die ("Error adding file: $file");
$zip->close();
}
// Random stuff below
}
Any help is greatly appreciated.
Thanks.
Do you have permissions to write on that folder in Mac?
Try with fopen instead of ZipArchive.

installing codeigniter sparks manager on windows

SOLVED, read bottom of post:
I'm trying to install the Sparks package manager on windows by following the official instructions.
Issuing this command:
php -r "$(curl -fsSL http://getsparks.org/go-sparks)"
results in this errormessage:
Parse error: syntax error, unexpected ':' in Command line code on line 1
If I only execute the curl command within the above line, i.e this:
curl -fsSL http://getsparks.org/go-sparks
it echoes out the php script located on the URL. So I think the problem is piping the curl output to PHP somehow fails. I've tried a couple of variants, using diffrent quotes etc but I'm at a loss.
MY SOLUTION
As DaveRandom pointed out, the instruction didn't apply to windows.
But instead of doing it the manual(normal) way, what I did was taking the output from curl, appending php script tags and executing it as a file with the php -f option.
Here is the output:
<?php
$zip = "http://getsparks.org/static/install/spark-manager-0.0.7.zip";
$loader = "http://getsparks.org/static/install/MY_Loader.php.txt";
if(!file_exists("application/core"))
{
echo "Can't find application/core. Currently this script only works with the default instance of Reactor. You may need to try a manual installation..\n";
exit;
}
echo "Pulling down spark manager from $zip ...\n";
copy($zip, "sparks.zip");
echo "Pulling down Loader class core extension from $loader ...\n";
copy($loader, "application/core/MY_Loader.php");
echo "Extracting zip package ...\n";
if(class_exists('ZipArchive'))
{
$zip = new ZipArchive;
if ($zip->open('sparks.zip') === TRUE)
{
$zip->extractTo('./tools');
$zip->close();
} else {
echo "Extraction failed .. exiting.\n";
exit;
}
} elseif(!!#`unzip`) {
`unzip sparks.zip -d ./tools`;
} else
{
echo "It seems you have no PHP zip library or `unzip` in your path. Use the manual installation.\n";
exit;
}
echo "Cleaning up ...\n";
#unlink('sparks.zip');
echo "Spark Manager has been installed successfully!\n";
echo "Try: `php tools/spark help`\n";
The instructions you linked do explicitly state;
In order to use this quick start option, you should be using OSX or some flavor of linux.
You need to follow the Normal Installation instructions for use on Windows.
You should execute the command php -r "$(curl -fsSL http://getsparks.org/go-sparks)" in your root application folder. Maybe you're executing this command at wrong folder.

Categories