Why this error coming call_user_func_array(): Cannot destroy the zip context: Can’t remove file: No such file or directory
Why this error coming call_user_func_array(): Cannot destroy the zip context: Can’t remove file: No such file or directory
There is no directory or file you are trying to remove. Make sure directory exist
$emp_id = Yii::$app->request->get(‘papl_id’);
$enrollment_table = Enrollment::find()->select([‘adhar_name’,‘browse_adhar’,‘browse_pp_photo’,‘browse_experience’,‘esic_sheet’,‘uan_sheet’])->where([‘enrolement_id’=>$emp_id])->one();
$family_table = Family::find()->select([‘family_nominee_adhar_photo’])->where([‘enrolement_id’=>$emp_id])->one();
$document_table = Document::find()->select([‘voter_copy_photo’,‘drivinglicense_photo’,‘pan_photo’,‘passport_photo’])->where([‘enrolement_id’=>$emp_id])->one();
$qualification_table = Qualification::find()->select([‘qualification_document’])->where([‘enrolement_id’=>$emp_id])->one();
$nominee_table = Nominee::find()->select([‘nominee_adhar_photo’])->where([‘enrolement_id’=>$emp_id])->one();
$doc_arr = [];
if($document_table){
$doc_arr[]=$document_table->drivinglicense_photo;
$doc_arr[]=$document_table->voter_copy_photo;
$doc_arr[]=$document_table->pan_photo;
$doc_arr[]=$document_table->passport_photo;
}
if($qualification_table){
$doc_arr[]=$qualification_table->qualification_document;
}
if ($enrollment_table) {
$doc_arr[]=$enrollment_table->browse_adhar;
$doc_arr[]=$enrollment_table->browse_pp_photo;
$doc_arr[]=$enrollment_table->browse_experience;
$doc_arr[]=$enrollment_table->esic_sheet;
$doc_arr[]=$enrollment_table->uan_sheet;
}
if ($family_table) {
$doc_arr[]=$family_table->family_nominee_adhar_photo;
}
if ($nominee_table) {
$doc_arr[]=$nominee_table->nominee_adhar_photo;
}
// temporary directory
$tempDir = sys_get_temp_dir();
// zip file name in full path
$zipFilePath = Yii::getAlias('@storage'). DIRECTORY_SEPARATOR ;
// $zipFilePath = Yii::getAlias('@storage'). DIRECTORY_SEPARATOR .'upload'. DIRECTORY_SEPARATOR ;
$zip = new ZipArchive();
// zip file name
$zipFileName = $zipFilePath."archive/doc_" . time() . ".zip";
if ($zip->open($zipFileName, ZipArchive::CREATE | ZipArchive::OVERWRITE) !== TRUE) {
die("Failed to create a zip archive. zipFilePath = $zipFilePath");
}
// file storage directory
$storage = Yii::getAlias('@storage'). DIRECTORY_SEPARATOR ;
if (!empty($doc_arr) || isset($doc_arr) || $doc_arr != '') {
foreach($doc_arr as $thefile)
{
if (!empty($thefile)) {
$zip->addFile($zipFilePath.$thefile);
$file_url = $storage.$thefile;
if(file_exists($file_url)){
$download_file = file_get_contents($file_url);
$zip->addFromString(basename($file_url),$download_file);
}else{
Yii::$app->session->setFlash('danger', "'No file found for download or '".$enrollment_table->adhar_name."' has missed some file to upload'");
return $this->redirect(['/posting-history/transfer']);
}
}
}
}
$zip->close();
header('Content-type: application/zip');
header('Content-Disposition: attachment; filename="'.basename($zipFileName).'"');
header("Content-length: " . filesize($zipFileName));
header("Pragma: no-cache");
header("Expires: 0");
ob_clean();
flush();
readfile($zipFileName);
unlink($zipFileName);
echo("Please see archive folder");
exit();`Preformatted text`
This is my code where is the issue???