Exemple #1
0
/**
 * Perform file uploading.
 * This function is a shortcut that avoids new Upload() object creation.
 * @param Upload $upload Waiting for upload object to be returned
 * @param mixed $extensions Collection of supported extensions, one extension is also supported
 * @param mixed $relativePathParameters Collection of parameters to be passed to external rel. path builder
 * @return bool True if file was successfully uploaded
 */
function uploadFile(&$upload, $extensions = array(), $relativePathParameters = null)
{
    // Create new Upload object
    $upload = new Upload($extensions, $relativePathParameters);
    // Return upload result
    return $upload->upload();
}
 /** Upload file controller */
 public function __async_upload()
 {
     /** @var \samsonphp\fs\FileService $fsModule */
     $fsModule = $this->system->module('fs');
     // Create object for uploading file to server
     $upload = new Upload(array(), $_GET['i']);
     // Uploading file to server;
     $upload->upload($file_path);
     // Call scale if it is loaded
     if (class_exists('\\samson\\scale\\ScaleController', false) && $this->isImage($fsModule->extension($file_path))) {
         /** @var \samson\scale\ScaleController $scale */
         $scale = $this->system->module('scale');
         $scale->resize($upload->fullPath(), $upload->name(), $upload->uploadDir);
     }
     // TODO: Work with upload real and URL paths
     $urlPath = $upload->path() . $upload->name();
     /** @var \samsoncms\input\Field $field Save path to file in DB */
     $this->createField(new dbQuery(), $_GET['e'], $_GET['f'], $_GET['i']);
     $this->field->save($urlPath);
     // Return upload object for further usage
     return array('status' => 1, 'path' => $urlPath);
 }
Exemple #3
0
 public function testFailedSync()
 {
     $this->instance->init();
     $upload = new Upload(array('gif', 'xls'), null, $this->instance, $this->getMockBuilder('\\samsonphp\\upload\\SyncHandler')->disableOriginalConstructor()->getMock());
     $upload->handler->expects($this->once())->method('name')->with($this->anything())->willReturn('samsonos.png');
     $_FILES = array('filename' => array('name' => 'samsonos.png', 'type' => 'image/jpeg', 'tmp_name' => 'tests/samsonos.png', 'error' => 0, 'size' => '1003'));
     $this->assertFalse($upload->async(false)->upload());
 }