本文整理汇总了PHP中Bluz\Proxy\Request::getFileUpload方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getFileUpload方法的具体用法?PHP Request::getFileUpload怎么用?PHP Request::getFileUpload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bluz\Proxy\Request
的用法示例。
在下文中一共展示了Request::getFileUpload方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createOne
/**
* createOne
*
* @param array $data
* @throws \Application\Exception
* @throws \Bluz\Request\RequestException
* @return integer
*/
public function createOne($data)
{
/**
* Process HTTP File
* @var \Bluz\Http\File $file
*/
$file = Request::getFileUpload()->getFile('file');
if (!$file or $file->getErrorCode() != UPLOAD_ERR_OK) {
if ($file->getErrorCode() == UPLOAD_ERR_NO_FILE) {
throw new Exception("Please choose file for upload");
}
throw new Exception("Sorry, I can't receive file");
}
/**
* Generate image name
*/
$fileName = strtolower(isset($data['title']) ? $data['title'] : $file->getName());
// Prepare filename
$fileName = preg_replace('/[ _;:]+/i', '-', $fileName);
$fileName = preg_replace('/[-]+/i', '-', $fileName);
$fileName = preg_replace('/[^a-z0-9.-]+/i', '', $fileName);
// If name is wrong
if (empty($fileName)) {
$fileName = date('Y-m-d-His');
}
// If file already exists, increment name
$originFileName = $fileName;
$counter = 0;
while (file_exists($this->uploadDir . '/' . $fileName . '.' . $file->getExtension())) {
$counter++;
$fileName = $originFileName . '-' . $counter;
}
// Setup new name and move to user directory
$file->setName($fileName);
$file->moveTo($this->uploadDir);
$this->uploadDir = substr($this->uploadDir, strlen(PATH_PUBLIC) + 1);
$data['file'] = $this->uploadDir . '/' . $file->getFullName();
$data['type'] = $file->getMimeType();
$row = $this->getTable()->create();
$row->setFromArray($data);
return $row->save();
}
示例2: createOne
/**
* @param array $data
* @throws Exception
* @throws \Bluz\Request\RequestException
* @return integer
*/
public function createOne($data)
{
/** @var \Bluz\Http\File $file */
$file = Request::getFileUpload()->getFile('image');
if (!$file or $file->getErrorCode() != UPLOAD_ERR_OK) {
if (!$file || $file->getErrorCode() == UPLOAD_ERR_NO_FILE) {
throw new Exception('Please choose file to upload');
}
throw new Exception('Sorry I can`t receive file');
}
$filename = $file->getName();
$name = explode(".", $filename);
$name[0] = uniqid($name[0]);
$filename = implode(".", $name);
$file->setName($filename);
$file->moveTo($this->uploadDir);
$data['file'] = $this->uploadDir . '/' . $file->getFullName();
$data['type'] = $file->getMimeType();
$row = $this->getTable()->create();
$row->setFromArray($data);
return $row->save();
}
示例3: upload
/**
* @param array $data
* @throws Exception
* @throws \Bluz\Request\RequestException
* @return integer
*/
public function upload()
{
/** @var \Bluz\Http\File $file */
$file = Request::getFileUpload()->getFile('files');
$type = $file->getType();
$row = new \Application\MusicianImage\Row();
$row->getTable()->create();
$row->setFromArray(['type' => $type]);
$row->beforeSave();
$row->afterSave();
if (!$file or $file->getErrorCode() != UPLOAD_ERR_OK) {
if (!$file || $file->getErrorCode() == UPLOAD_ERR_NO_FILE) {
throw new Exception('Please choose file to upload');
}
throw new Exception('Sorry I can`t receive file');
}
$name = uniqid();
$filename = $name . "." . $file->getExtension();
$file->setName($name);
$file->moveTo($this->uploadDir);
Session::set('image', $filename);
return $file;
}
示例4: createOne
public function createOne()
{
//get saved data
$existFilesData = Session::get('files');
$files = unserialize($existFilesData);
//get paths to upload directory
$path = Config::getModuleData('menu', 'full_path');
$relativePath = Config::getModuleData('menu', 'relative_path');
//get new file,that saved in /tmp directory
$newFileData = Request::getFileUpload()->getFile('files');
$editor = new Manager($newFileData, $path);
//validate file name
$editor->renameFileName();
//merge new and exist files data
if ($existFilesData) {
$fileObjects = $files;
$fileObjects[uniqid()] = $editor->getFile();
} else {
$fileObjects = [uniqid() => $editor->getFile()];
}
Session::set('files', serialize($fileObjects));
$file = $editor->getFile();
return array('id' => array_search($editor->getFile(), $fileObjects), 'path' => $relativePath . $file->getName() . '.' . $file->getExtension());
}
示例5: testFileUploadWithThreeSubKey
/**
* Test FileUpload with three sub key
*/
public function testFileUploadWithThreeSubKey()
{
$_FILES = array('file' => array('name' => array('a' => array('b' => array('test.jpeg', 'test1.jpeg'))), 'size' => array('a' => array('b' => array(filesize($this->path1), filesize($this->path2)))), 'type' => array('a' => array('b' => array('image/jpeg', 'image/jpeg'))), 'tmp_name' => array('a' => array('b' => array($this->path1, $this->path2))), 'error' => array('a' => array('b' => array(0, 0)))));
$result = Request::getFileUpload()->getFiles('file[a][b]');
$this->assertNotEmpty($result);
}
示例6: function
*/
/**
* @namespace
*/
namespace Application;
use Bluz\Config\ConfigException;
use Bluz\Http\File;
use Bluz\Proxy\Config;
use Bluz\Proxy\Request;
return function () {
/**
* @var Bootstrap $this
* @var \Bluz\Http\FileUpload $fileUpload
*/
$fileUpload = Request::getFileUpload();
$file = $fileUpload->getFile('file');
if ($file && $file->getType() == File::TYPE_IMAGE) {
// save original name
$original = $file->getName();
// rename file to date/time stamp
$file->setName(date('Ymd_Hi'));
// switch to JSON response
$this->useJson();
if (!$this->user()) {
throw new Exception('User not found');
}
$userId = $this->user()->id;
// directory structure:
// uploads/
// %userId%/