本文整理汇总了PHP中UploadedFile::getRelativePath方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadedFile::getRelativePath方法的具体用法?PHP UploadedFile::getRelativePath怎么用?PHP UploadedFile::getRelativePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadedFile
的用法示例。
在下文中一共展示了UploadedFile::getRelativePath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveUploadedFileCallback
/**
* Save uploaded file callback
* @param UploadedFile $uploadedFile
*/
public function saveUploadedFileCallback($uploadedFile)
{
if (empty($this->_destination)) {
return;
}
/* @var $uploadedFile UploadedFile */
$relativePath = $uploadedFile->getRelativePath();
if (empty($relativePath)) {
$basePath = $this->_destination;
} else {
$relativePath = trim($relativePath, '/\\');
$relativePath = preg_replace('#\\/#', DIRECTORY_SEPARATOR, $relativePath);
$basePath = $this->_destination . DIRECTORY_SEPARATOR . $relativePath;
}
if (!is_dir($basePath)) {
mkdir($basePath, 0777, true);
}
$basePath .= DIRECTORY_SEPARATOR;
foreach ($uploadedFile->getConvertedFiles() as $convertedFile) {
/* @var $convertedFile ConvertedFile */
$name = $convertedFile->getName();
$path_info = pathinfo($name);
$i = 2;
$fullFilePath = $basePath . $name;
while (file_exists($fullFilePath)) {
$fullFilePath = $basePath . $path_info['filename'] . '_' . $i . '.' . $path_info['extension'];
$i++;
}
$convertedFile->moveTo($fullFilePath);
}
}