Ejemplo n.º 1
0
 public function testExtension()
 {
     $this->instance->init();
     $upload = new Upload(array('xls', 'gif'), null, $this->instance, $this->getMockBuilder('\\samsonphp\\upload\\AsyncHandler')->disableOriginalConstructor()->getMock());
     $upload->handler->expects($this->once())->method('name')->willReturn('tests/samsonos.png');
     $this->assertFalse($upload->upload());
 }
Ejemplo n.º 2
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();
}
Ejemplo n.º 3
0
 /** 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);
 }