本文整理汇总了PHP中FileUtils::mkpath方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtils::mkpath方法的具体用法?PHP FileUtils::mkpath怎么用?PHP FileUtils::mkpath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileUtils
的用法示例。
在下文中一共展示了FileUtils::mkpath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: putIn
/**
* In this method, we don't modify tmp_name attribute
* rather than that, we set the saved_path attribute
* for location of these moved files.
*/
public function putIn($targetDir, $targetFileName = null, $useCopy = false)
{
/* source file */
$file = $this->tmp_name;
if (!file_exists($file) && isset($_FILES[$this->column]['saved_path'])) {
$useCopy = true;
$file = $_FILES[$this->column]['saved_path'];
}
// if targetFilename is not given,
// we should take the filename from original filename by using basename.
if (!$targetFileName) {
$targetFileName = basename($this->name);
}
// make sure we have the directory exists.
if (!file_exists($targetDir)) {
FileUtils::mkpath($targetDir);
}
// relative file path.
$newPath = FileUtils::path_join($targetDir, $targetFileName);
/* avoid file name duplication */
$fileCnt = 1;
while (file_exists($newPath)) {
$newPath = FileUtils::path_join($targetDir, FileUtils::filename_suffix($targetFileName, '_' . $fileCnt++));
// substr(md5_file( $file ),0,5) . '_' . $targetFileName );
}
/* register to $_FILES[ name ][ savedpath ]
*
* in CRUD action, we need to validate if a action file column's value
* is a real upload file.
* */
$this->saved_path = $newPath;
if ($useCopy) {
copy($file, $newPath);
} else {
$this->move($file, $newPath);
}
$_FILES[$this->column]['saved_path'] = $newPath;
return $newPath;
}