<?php $oUploads = new weeUploads(); foreach ($oUploads->filter('myfiles') as $oFile) { doSomething($oFile); }
<?php $oUploads = new weeUploads(); if ($oUploads->exists('myfile')) { $oFile = $oUploads->fetch('myfile'); doSomething($oFile); }
<?php $oUploads = new weeUploads(); $oFile = $oUploads->fetch('myfile'); if ($oFile->isOK()) { $oFile->moveTo('/path/to/destination/folder'); } else { echo $oFile->getError(); }
<?php define('ALLOW_INCLUSION', 1); define('DEBUG', 1); define('ROOT_PATH', '../../../'); require ROOT_PATH . 'wee/wee.php'; $iStep = array_value($_GET, 'step', 1); // The cURL PHP extension is required to run this test. function_exists('curl_init') or die('skip'); try { $o = new weeUploads(); $sURL = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '&upload=1'; if ($iStep == 1) { if ($o->isEmpty()) { empty($_GET['upload']) or burn('IllegalStateException', _WT('No file was uploaded. Stopping here in order to prevent recursive execution.')); $r = curl_init(); curl_setopt($r, CURLOPT_URL, $sURL); curl_setopt($r, CURLOPT_POST, true); curl_setopt($r, CURLOPT_POSTFIELDS, array('test' => '@' . dirname(__FILE__) . '/test.txt')); curl_exec($r) or burn('UnitTestException', sprintf(_WT('Upload failed: %s'), curl_error($r))); curl_close($r); exit; } else { $o->exists('test') or burn('UnitTestException', _WT('The uploaded file "test" does not exist.')); $oFile = $o->fetch('test'); $oFile->isOK() or burn('UnitTestException', sprintf(_WT('Upload error: %s'), $oFile->getError())); try { $oFile->getError(); burn('UnitTestException', _WT('weeUploadedFile::getError should throw an IllegalStateException when file uploaded correctly.')); } catch (IllegalStateException $e) { }
/** Move the uploaded file to the destination folder. @param $sDest Destination folder for the file. @param $sName Name of the uploaded file. */ function upload_move_to($sDest, $sName = 'file') { $oUploads = new weeUploads(); $oFile = $oUploads->fetch($sName); $oFile->isOK() or burn('UnexpectedValueException', _WT(sprintf('Upload of the file %s failed with the following error: %s', $oFile->getFilename(), $oFile->getError()))); $oFile->moveTo($sDest); }