0

I have solve the previous problem and now it create a zip file and add all the files from a specific folder, but the zip file is not where I want it to be, the zip file is just in the public folder, how do I make it so that the zip file is created and in the company folder?

$companyLogoURL = '';
if ($companyLogo) {
    //create folder if not exist
    $destinationPath = 'uploads/company/';
    if (! file_exists($destinationPath)) {
        mkdir($destinationPath, 0777, true);
    }

    $imageExt = $companyLogo->getClientOriginalExtension();
    $imageName = time().$customer_id.'.'.$imageExt;
    $imageFormats = ['jpg', 'png', 'gif', 'bmp', 'jpeg', 'PNG', 'JPG', 'JPEG', 'GIF', 'BMP','svg'];

    //check video validation
    $getFileSize = $companyLogo->getSize();
    if ($getFileSize <= $this::FILE_SIZE_THREE_MB) {
        if (in_array($imageExt, $imageFormats)) {
            $companyLogo->move($destinationPath, $imageName);
            $companyLogoURL = $imageName;

            $zip = new ZipArchive();
            $zip_name = $imageName.".zip";
            if($zip->open(public_path($zip_name), ZIPARCHIVE::CREATE)===TRUE){
            
                $files = File::files(public_path('uploads/company'));
                foreach($files as $key => $value){
                    $samefileNameinZip = basename($value);
                    $zip->addFile($value, $samefileNameinZip);
                }
                $zip->close(); 
            }
        }

Please let me know if you have any advice or anything I did wrong that you notice.

Thank you, much appreciated.

  • Do you get any errors/warnings? any output? Do you get the "Not working!!" message you've added? – Ofir Baruch Sep 13 '21 at 19:02
  • How is this question different from [your last question](https://stackoverflow.com/questions/69148225/how-do-i-zip-the-files-first-before-they-are-uploaded)? – j08691 Sep 13 '21 at 19:02
  • No, I did not get any error, it just doesn't create a zip folder or add the files into the zip folder. – nung khual Sep 14 '21 at 04:47

2 Answers2

0

First I would try to give the absolute path for the file to make sure that I go to the correct directory. I would also check the folder permissions.

tkouleris
  • 1
  • 1
  • Yes, the directory seem to be correct as far as I am concern, I am using laravel and the directory is in the public folder, so I believe there isn't any issue with the folder permission. – nung khual Sep 14 '21 at 04:48
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 14 '21 at 05:32
0

Try the following to check the error:

$result = $zip->open($zip_name, ZIPARCHIVE::CREATE);

if($result !==TRUE){

   dd($result)

}
Kemal Kaplan
  • 932
  • 8
  • 21
tkouleris
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-ask). – Community Sep 14 '21 at 08:43