本文整理汇总了PHP中DxdUtil::fileExt方法的典型用法代码示例。如果您正苦于以下问题:PHP DxdUtil::fileExt方法的具体用法?PHP DxdUtil::fileExt怎么用?PHP DxdUtil::fileExt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DxdUtil
的用法示例。
在下文中一共展示了DxdUtil::fileExt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: clearCaches
/**
* 找出某一图片文件对应的所有缓存文件
* Enter description here ...
* @param unknown_type $fileName
*/
public static function clearCaches($fileName)
{
if ($fileName) {
$ext = DxdUtil::fileExt($fileName);
$pattern = substr($fileName, 0, strrpos($fileName, ".")) . "_*." . $ext;
$pattern = Yii::app()->basePath . "/../caches/" . $pattern;
$cacheFiles = glob($pattern);
foreach ($cacheFiles as $file) {
if (file_exists($file)) {
unlink($file);
}
}
}
}
示例2: handleUploading
/**
* Uploads file to temporary directory
*
* @throws CHttpException
*/
protected function handleUploading()
{
$this->init();
$model = $this->formModel;
$model->{$this->fileAttribute} = CUploadedFile::getInstance($model, $this->fileAttribute);
if ($model->{$this->fileAttribute} !== null) {
$model->{$this->mimeTypeAttribute} = $model->{$this->fileAttribute}->getType();
$model->{$this->sizeAttribute} = $model->{$this->fileAttribute}->getSize();
$model->{$this->displayNameAttribute} = $model->{$this->fileAttribute}->getName();
$model->{$this->fileNameAttribute} = $model->{$this->displayNameAttribute};
if ($model->validate()) {
$path = $this->getPath();
if (!is_dir($path)) {
mkdir($path, 0777, true);
chmod($path, 0777);
}
//added by liang begine 130815
$newFilePath = $path . $model->{$this->fileNameAttribute};
$i = 1;
while (file_exists($newFilePath) && $i < 10000) {
$ext = DxdUtil::fileExt($newFilePath);
$newFilePath = substr($newFilePath, 0, strrpos($newFilePath, "."));
$newFilePath = $newFilePath . "(" . $i . ")." . $ext;
$i++;
}
//added by liang end
// $model->{$this->fileAttribute}->saveAs($path . $model->{$this->fileNameAttribute});
$model->{$this->fileAttribute}->saveAs($newFilePath);
// chmod($path . $model->{$this->fileNameAttribute}, 0777);
chmod($newFilePath, 0777);
$returnValue = $this->beforeReturn();
if ($returnValue === true) {
echo json_encode(array(array("name" => $model->{$this->displayNameAttribute}, "type" => $model->{$this->mimeTypeAttribute}, "size" => $model->{$this->sizeAttribute}, "url" => $this->getFileUrl($model->{$this->fileNameAttribute}), "thumbnail_url" => $model->getThumbnailUrl($this->getPublicPath()), "delete_url" => $this->getController()->createUrl($this->getId(), array("_method" => "delete", "file" => $model->{$this->fileNameAttribute})), "delete_type" => "POST")));
} else {
echo json_encode(array(array("error" => $returnValue)));
Yii::log("XUploadAction: " . $returnValue, CLogger::LEVEL_ERROR, "xupload.actions.XUploadAction");
}
} else {
echo json_encode(array(array("error" => $model->getErrors($this->fileAttribute))));
Yii::log("XUploadAction: " . CVarDumper::dumpAsString($model->getErrors()), CLogger::LEVEL_ERROR, "xupload.actions.XUploadAction");
}
} else {
throw new CHttpException(500, "Could not upload file");
}
}