Gargron / fileupload

PHP FileUpload library that supports chunked uploads
MIT License
460 stars 87 forks source link

get the file name #59

Closed blsn closed 6 years ago

blsn commented 6 years ago

list($files, $headers) = $fileupload->processAll(); echo json_encode(['files' => $files]);

Two files were uploaded. file name visible only for validation file error:

{"files":[{"error":"Filetype not allowed","errorCode":0,"completed":false,"name":"header-image.jpg","size":72193},{"error":0,"errorCode":0,"completed":true,"size":2254}]}

How to get the file name?

adelowo commented 6 years ago
list($files, $headers) = $fileUpload->processAll();

foreach($files as $file) {
    //Regardless of the validation status - failed or not you do this
    echo $file->getFilename();
}

$file->name should also get you there

blsn commented 6 years ago

This will work only as follows:

        foreach($files as $file) {
            if ($file->completed) { // check if the upload was completed
                echo $file->getFilename();
            }
        }       

But how can I get the file names for both completed/uncompleted?