Example #1
0
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) {
        if ($o->isEmpty()) {
Example #2
0
<?php

$oUploads = new weeUploads();
if ($oUploads->exists('myfile')) {
    $oFile = $oUploads->fetch('myfile');
    doSomething($oFile);
}
Example #3
0
/**
	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);
}