Zip archive is not extract the file showing 19 error message - php

$json_path = BUILDERUX_JSON_UPLOAD . $json_folder . '/';
$zip = new ZipArchive;
$res = $zip->open(BUILDERUX_JSON_UPLOAD.$filename);
if ($res === TRUE)
{
echo "working1";
$zip->extractTo($json_path);
$zip->close();
}
path is correct but file is not extract and getting 19 error message .
Im having issues with my code being able to open a zip file that i have uploaded and moved into a folder, the zip file uploads fine and you can open it in any Zip program however, when i attempt to open it with ZipArchive to extract the data it errors.
When i run the code it shows me a Error Code 19

Having a look at the docs and this entry, error code 19 could be that the file is not a zip archive.

Related

Extract Zip File from remote server with white-space in file name

I have a list of zip files to read from a remote server. The list of the files are as follows:
CA-EN Bosch 20170901.zip
CA-EN Gaggenau 20170901.zip
CA-EN Thermador 20170901.zip
As we can see here, all filenames are with white-space in it. Due to this My code is unable to extract these zip files.
Following is what I am using to extract file contents:
$destination = '../../boschzip';
$zip = new ZipArchive;
$res = $zip->open('CA-EN Bosch 20170901.zip'); // Your filename
if ($res === TRUE) {
$zip->extractTo('../../boschzip');
$zip->close();die;
}
else{
echo 'Error Message. :(';die;
}
I can not make any change in the file name as it is on the client's server. So is it possible to extract these zip files with white-space in their file names.

PHP ZipArchive doesn't create a zip archive. What to fix in the code?

I have an .srt file located in the files/srt/username/filename.srt directory. I need to be able to download it in the browser, but to make this possible I have to zip the file first.
I found the following code online:
function download_zip() {
if (isset($_POST['download_srt'])) {
$zip = new ZipArchive();
$zip->open("files/srt/".$_SESSION['user_name']."/".$_POST['download_srt'].".zip", ZipArchive::CREATE);
// output: files/srt/username/filename.srt.zip
$zip->addFile($_POST['download_srt']);
// output of $_POST['download_srt']: filename.srt
$zip->close();
}
}
The code is called when a submit button is pressed and the $_POST data are sent.
The function works, but no ZIP file gets created in the same directory as the original srt file. No error messages appear.
You should provide the correct path to the file to add:
$zip->addFile("files/srt/".$_SESSION['user_name']."/".$_POST['download_srt']);

ftp_put() error failed to open stream: No such file or directory

So i am trying to create a php on webhost allow client to upload files to the webhost then webhost use ftp_put to upload file to another ftp server. The following function is used for upload the file.
//upload ftp
function ftp_upload($conn, $vid_name, $video){
//get tmp file
$file_tmp_name = $video['tmp_name'];
echo $file_tmp_name;
//combine name with extension name
$server_file_name = $vid_name . "." . pathinfo($video['name'],PATHINFO_EXTENSION);
//upload video
$upload = ftp_put($conn, $server_file_name, $file_tmp_name , FTP_BINARY);
return $upload;
}
However it keeps getting the error msg,
Warning: ftp_put(/tmp/phpKOtNWK) [function.ftp-put]: failed to open stream: No such file or director.
So i went to the file manager in the webhost under my subdomain, there is no such directory called tmp, and i don't have privilege to enter the root directory for the webhost.
appreciate for your helps.
So thanks to Twisty 23 and Jon Stirling's advices, i've solved the issue. Unfortunately noone posted answer(all comments) which bugs me to keep this unsolved, so i'll just answer myself.
This is the code i used at the beginning to redirect
//store video information into session
if(count($_POST) >0 ){
$_SESSION['vid_name'] = $_POST['vid_name'];
$_SESSION['video'] = $_FILES['video'];
//move tmp file to permanent location temp folder
move_uploaded_file($_FILES['video']['tmp_name'], "./temp/" . $_POST['vid_name'] . ".tmp");
//change tmp location to temp folder
$_SESSION['video']['tmp_name'] = "./temp/" . $_POST['vid_name'] . ".tmp";
//redirect
header("Location: " . $_SERVER['REQUEST_URI']);
die();
}
and then i don't need to change anything on ftp_upload function, i can use $_SESSION['video']['tmp_name'] straight away.

Creating zip file with php

I am creating a zip file of a particular folder, I am using joomla 1.5 version in which i have a component of form submission and I want to create a zip file with submitted documents. On my localhost, its creating the zip file, when I test to remote server, It replaces the extension with some kind of a number, suppose we are creating a file test.zip, but its creating like this test.zip.a12345 and test.zip.b12345..
The code which I have used to create zip file:
$files = array(
'files/file1.jpg',
'files/file2.jpg',
'files/file3.jpg'
);
$zip = new ZipArchive();
$zip_name = "zipfile.zip";
if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE){
$error .= "* Sorry ZIP creation failed at this time";
}
foreach($files as $file){
$zip->addFile($file);
}
$zip->close();
and the output on local server is zipfile.zip
output on live server is : zipfile.zip.a11236 and zipfile.zip.b11236
You probably need to use the ZipArchive::OVERWRITE flag when opening the file.
It chooses another name because the file already exists?
See: http://php.net/manual/en/zip.constants.php

Unzip The Zip Archive With PHP

I Have A Problem About extract the zip file with PHP
I try many shared script on the web
but it still doesn't work
the last script i try is this script :
<?php
$zip = new ZipArchive;
$res = $zip->open('data.zip');
if ($res === TRUE) {
$zip->extractTo('/extract/');
$zip->close();
echo 'woot!';
} else {
echo 'doh!';
}
?>
I am always get the else condition when the script is run ,
I've tried replacing the data.zip and the /extract/ path to complete path http://localhost/basedata/data.zip and http://localhost/basedata/extract/ but I still got the else condition , Anyone can help me?
Here Is My whole script and the zip file
http://www.mediafire.com/?c49c3xdxjlm58ey
You should check which error code gives open (http://www.php.net/manual/en/ziparchive.open.php), that will give you some help.
Error codes are this:
ZIPARCHIVE::ER_EXISTS -10
ZIPARCHIVE::ER_INCONS - 21
ZIPARCHIVE::ER_INVAL - 18
ZIPARCHIVE::ER_MEMORY - 14
ZIPARCHIVE::ER_NOENT - 9
ZIPARCHIVE::ER_NOZIP - 19
ZIPARCHIVE::ER_OPEN - 11
ZIPARCHIVE::ER_READ - 5
ZIPARCHIVE::ER_SEEK - 4
ZipArchive uses file paths, not URLs.
For example, if your web server's document root is /srv/www, specify /srv/www/basedata/data.zip (or wherever the file is on the server's local file system), not http://localhost/basedata/data.zip.
If the .ZIP file is on a remote computer, change the script to download it first before extracting it, though this does not seem to be your case.
Furthermore, the user the PHP script runs as needs to have read permission for the Zip file and write permission for the destination for extracted files.
you are declaring your $zip (ziparchive) incorrectly
<?php
$zip = new ZipArchive;
is missing parentheses
<?php
$zip = new ZipArchive();
if ($zip->open('data.zip')) {

Categories