首页 > 解决方案 > Laravel filesize(): stat failed

问题描述

I have a function to download some files. It works on localhost however, after I upload it on GoDaddy I get an exception.

ErrorException (E_WARNING) filesize(): stat failed for

$zip->open($zip_name, ZipArchive::CREATE);
if ($number_of_files >= 1) {
    if ($param === 'documents') {
        foreach ($file as $files) {
            for ($i = 1; $i <= 6; $i++) {
                $path = public_path()."/documents/".$files->$i;
                if (file_exists($path)) {
                    $zip->addFromString($files->$i, file_get_contents($path));
                }
            }
        }
    } else {
        foreach ($file as $files) {
            $path = public_path().'/safetySystemsSchema/'.$files->title;
            if (file_exists($path)) {
                $zip->addFromString($files->title, file_get_contents($path));
            }
        }
    }
    $zip->close();
    $headers = [
        'Content-Type: application/zip',
        'Content-disposition: attachment; filename='.$zip_name,
        'Content-Length: '.filesize($zip_name)
    ];
    response()->download($zip_name, $zip_name, $headers);

    return Response::download($zip_name)->deleteFileAfterSend(true);
}

标签: phplaravel

解决方案


推荐阅读