本文整理汇总了PHP中UploadedFile::move方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::move方法的具体用法?PHP UploadedFile::move怎么用?PHP UploadedFile::move使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::move方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload()
{
if (null === $this->file) {
return;
}
$this->file->move($this->getUploadRootDir(), $this->path);
unset($this->file);
}
示例2: moveUploadedFile
public function moveUploadedFile(UploadedFile $file, $uploadBasePath)
{
$originalName = $file->getOriginalName();
// use filemtime() to have a more determenistic way to determine the subpath, otherwise its hard to test.
$relativePath = date('Y-m', filemtime($this->file->getPath()));
$targetFileName = $relativePath . DIRECTORY_SEPARATOR . $originalName;
$targetFilePath = $uploadBasePath . DIRECTORY_SEPARATOR . $targetFileName;
$ext = $this->file->getExtension();
$i = 1;
while (file_exists($targetFilePath) && md5_file($file->getPath()) != md5_file($targetFilePath)) {
if ($ext) {
$prev = $i == 1 ? "" : $i;
$targetFilePath = $targetFilePath . str_replace($prev . $ext, $i++ . $ext, $targetFilePath);
} else {
$targetFilePath = $targetFilePath . $i++;
}
}
$targetDir = $uploadBasePath . DIRECTORY_SEPARATOR . $relativePath;
if (!is_dir($targetDir)) {
$ret = mkdir($targetDir, umask(), true);
if (!$ret) {
throw new \RuntimeException("Could not create target directory to move temporary file into.");
}
}
$file->move($targetDir, basename($targetFilePath));
return str_replace($uploadBasePath . DIRECTORY_SEPARATOR, "", $targetFilePath);
}
示例3: upload
/**
* @ORM\PostPersist()
* @ORM\PostUpdate()
*/
public function upload()
{
if (null === $this->file) {
return;
}
// if there is an error when moving the file, an exception will
// be automatically thrown by move(). This will properly prevent
// the entity from being persisted to the database on error
// moving file into /data
$this->file->move($this->getUploadRootDir(), $this->path);
// creating symlink to acces file from web/...
symlink($this->getUploadRootDir() . '/' . $this->path, $this->getWebPath());
unset($this->file);
}
示例4: saveFile
protected function saveFile(UploadedFile $file)
{
$upload_dir = public_path('uploads/');
$file_name = 'file-' . date('dmY-His') . '.' . $file->getClientOriginalExtension();
try {
if ($file->move($upload_dir, $file_name)) {
return $file_name;
} else {
return false;
}
} catch (\Exception $ex) {
return abort(500, $ex->getMessage());
}
}
示例5: upload
/**
* @param UploadedFile $file
*
* @param null $filename
* @return null|string
*/
private function upload(UploadedFile $file, $filename = null)
{
if ($file && $file->isValid()) {
if (!Storage::exists('page_image')) {
Storage::makeDirectory('page_image');
}
if ($filename === null) {
$filename = $this->getUniqueName('page_image', $file->getClientOriginalExtension());
}
$file->move('page_image', $filename);
return $filename;
}
return null;
}