path to an uploaded filename

tshirley 24 Jan, 2017
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:


$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
GreyHead 24 Jan, 2017
Hi Tim,

Try using the Joomla! constant for the start of the path:
$path = JPATH_SITE.'/components/com_chronoforms5/chronoforms/uploads/myFileUpload/';

Bob
tshirley 24 Jan, 2017
Thanks Bob,

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
GreyHead 24 Jan, 2017
Hi Tim,

It might be a namespace problem; please try
$zip = new \ZipArchive;
or the Joomla! version
jimport( 'joomla.filesystem.archive.zip' );
$zip = new \JArchiveZip;
which has an isSupported() method.

Bob
tshirley 24 Jan, 2017
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
Max_admin 25 Jan, 2017
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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
tshirley 25 Jan, 2017
Thanks Max,

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
Max_admin 30 Jan, 2017
hi Tim,

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
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger