PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Checking Files

Zend_File_Transfer has several methods that check for various states of the specified file. These are useful if you must process files after they have been uploaded. These methods include:

  • isValid($files = null): This method will check if the given files are valid, based on the validators that are attached to the files. If no files are specified, all files will be checked. You can call isValid() before calling receive(); in this case, receive() will not call isValid() internally again when receiving the file.

  • isUploaded($files = null): This method will check if the specified files have been uploaded by the user. This is useful when you have defined one or more optional files. When no files are specified, all files will be checked.

  • isReceived($files = null): This method will check if the given files have already been received. When no files are specified, all files will be checked.

Example 400. Checking Files

<?php
$upload 
= new Zend_File_Transfer();

// Returns all known internal file information
$files $upload->getFileInfo();

foreach (
$files as $file => $info) {
    
// file uploaded ?
    
if (!$upload->isUploaded($file)) {
        print 
"Why havn't you uploaded the file ?";
        continue;
    }

    
// validators are ok ?
    
if (!$upload->isValid($file)) {
        print 
"Sorry but $file is not what we wanted";
        continue;
    }
}

$upload->receive();

Zend Framework