<?php $oUploads = new weeUploads(); if ($oUploads->exists('myfile')) { $oFile = $oUploads->fetch('myfile'); doSomething($oFile); }
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) { } $oFile->getExt() == 'txt' or burn('UnitTestException', _WT('The extension of the uploaded file is incorrect.')); touch('/tmp/test.txt'); $oFile->fileExists('/tmp/') or burn('UnitTestException', _WT('weeUploadedFile::fileExists should have reported that the file exists.')); $oFile->moveTo('/tmp/'); file_get_contents('/tmp/test.txt') == "This file is a test file upload.\n" or burn('UnitTestException', _WT('The contents of the uploaded file are incorrect.')); unlink('/tmp/test.txt'); } } elseif ($iStep == 2) {