Hi all,
I need to create a zip archive from a file uploaded in a CF5 form.
The file is in "/public_html/mydomain/components/com_chronoforms5/chronoforms/uploads/myFileUpload/"
So I created the following:
which doesn't work...in fact, gives a "this site is not working" response.
I am guessing that the problem lies with the path and it is probably a simple mistake.
Cheers
Tim
I need to create a zip archive from a file uploaded in a CF5 form.
The file is in "/public_html/mydomain/components/com_chronoforms5/chronoforms/uploads/myFileUpload/"
So I created the following:
$zip = new ZipArchive;
$path="/public_html/mydomain/components/com_chronoforms5/chronoforms/uploads/myFileUpload/";
if ($zip->open($path.'test_new.zip', ZipArchive::CREATE) === TRUE)
{
// Add files to the zip file
$zip->addFile($path.'uploadedfile.txt');
// All files are added, so close the zip file.
$zip->close();
which doesn't work...in fact, gives a "this site is not working" response.
I am guessing that the problem lies with the path and it is probably a simple mistake.
Cheers
Tim
Hi Tim,
Try using the Joomla! constant for the start of the path:
Bob
Try using the Joomla! constant for the start of the path:
$path = JPATH_SITE.'/components/com_chronoforms5/chronoforms/uploads/myFileUpload/';
Bob
Thanks Bob,
After trying
it gave the same result - error 500, this site is not working.
Is it possible that the ZipArchive is not loaded? How would I be able to check?
Cheers
Tim
After trying
$path = JPATH_SITE."/components/com_chronoforms5/chronoforms/uploads/myFileUpload/";
it gave the same result - error 500, this site is not working.
Is it possible that the ZipArchive is not loaded? How would I be able to check?
Cheers
Tim
Hi Tim,
It might be a namespace problem; please try
Bob
It might be a namespace problem; please try
$zip = new \ZipArchive;
or the Joomla! versionjimport( 'joomla.filesystem.archive.zip' );
$zip = new \JArchiveZip;
which has an isSupported() method.
Bob
Hi Bob,
I get the same error (500) with all these methods, which suggest that there may be something more fundamental I am doing wrong. Can't see it though.
The background is that I am using an API that requires a zip file to be uploaded rather than the raw files and so I am looking for a way to create the zip file after the file is uploaded in CF5.
Cheers
Tim
I get the same error (500) with all these methods, which suggest that there may be something more fundamental I am doing wrong. Can't see it though.
The background is that I am using an API that requires a zip file to be uploaded rather than the raw files and so I am looking for a way to create the zip file after the file is uploaded in CF5.
Cheers
Tim
Hi Tim,
Can you set the site "error reporting" to maximum under the Joomla global config ? that should show if there is an error with your code.
Best regards,
Max
Can you set the site "error reporting" to maximum under the Joomla global config ? that should show if there is an error with your code.
Best regards,
Max
Thanks Max,
The code is:
and the error is:
This is a bit outside my php expertise level, so apologies if it is something simple.
Cheers
Tim
The code is:
jimport( 'joomla.filesystem.archive.zip' );
$zip = new \JArchiveZip;
$path = JPATH_SITE."/components/com_chronoforms5/chronoforms/uploads/MyFileUpload/";
$file = array($path.'myfile.txt');
if (\JArchiveZip::create( $path."testzip.zip", $file)) echo "OK";
and the error is:
Deprecated: Non-static method JArchiveZip::create() should not be called statically, assuming $this from incompatible context in /home/glidinga/public_html/mydomain/administrator/components/com_chronoforms5/chronoforms/actions/custom_code/custom_code.php(20) : eval()'d code on line 10
Fatal error: Call to undefined method GCore\Admin\Extensions\Chronoforms\Actions\CustomCode\CustomCode::_addToZIPFile() in /home/glidinga/public_html/mydomain/libraries/joomla/archive/zip.php on line 115
This is a bit outside my php expertise level, so apologies if it is something simple.
Cheers
Tim
hi Tim,
Please try to change this line:
to:
Best regards,
Max
Please try to change this line:
if (\JArchiveZip::create( $path."testzip.zip", $file)) echo "OK";
to:
if ($zip->create( $path."testzip.zip", $file)) echo "OK";
Best regards,
Max
This topic is locked and no more replies can be posted.