本文整理汇总了PHP中CUploadedFile::clean方法的典型用法代码示例。如果您正苦于以下问题:PHP CUploadedFile::clean方法的具体用法?PHP CUploadedFile::clean怎么用?PHP CUploadedFile::clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CUploadedFile
的用法示例。
在下文中一共展示了CUploadedFile::clean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveImg
/**
* Processes the uploaded image.
* @param CUploadedFile $uploadedImg The uploaded image
* @param string $title The title (or caption) of this image (optional)
* @param string $description The detailed description of this image (optional)
* @param string $albumName The name of the album to put the image in (optional)
* @return string The ID of new uploaded image | false
*/
private function saveImg($uploadedImg, $title = '', $description = '', $albumName = '')
{
// Key
$userId = CassandraUtil::import(Yii::app()->user->getId())->__toString();
$key = $userId . '_' . CassandraUtil::uuid1();
// Path
$path = realpath(Yii::app()->params['storagePath']) . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . $userId;
if (!is_dir($path)) {
mkdir($path, 0775);
}
if (!empty($albumName)) {
$path .= DIRECTORY_SEPARATOR . $albumName;
}
if (!is_dir($path)) {
mkdir($path, 0775);
}
// Save the image information before processing the image
$data = array('storage_path' => $uploadedImg->getTempName(), 'mime_type' => $uploadedImg->getType(), 'extension' => $uploadedImg->getExtensionName(), 'user_id' => Yii::app()->user->getId());
if (!empty($title)) {
$data['title'] = $title;
}
if (!empty($description)) {
$data['description'] = $description;
}
if ($this->insert($key, $data) === false) {
$uploadedImg->clean();
return false;
}
// Render this image into different versions
$photoTypes = Setting::model()->photo_types;
// Get list of image types in JSON format. Decode it.
$photoTypes = json_decode($photoTypes['value'], true);
$img = Yii::app()->imagemod->load($data['storage_path']);
$convertedImgs = array();
foreach ($photoTypes as $type => $config) {
$img->image_convert = 'jpg';
$img->image_resize = true;
$img->image_ratio = true;
$img->image_x = $config['width'];
$img->image_y = $config['height'];
if (isset($config['suffix'])) {
$img->file_safe_name = $key . $config['suffix'] . '.jpg';
} else {
$img->file_safe_name = $key . '.jpg';
}
$img->process($path);
if (!$img->processed) {
// Delete the original image
$uploadedImg->clean();
// Delete the record in db
$this->delete($key);
// Log the error
Yii::log('Cannot resize the image ' . $data['storage_path'] . ' to ' . $path . '/' . $img->file_safe_name, 'error', 'application.modules.storage.Storage');
// Delete all converted images
foreach ($convertedImgs as $imgType => $imgPath) {
unlink($imgPath);
}
// Return false
return false;
} else {
// Remember the path of converted image
$convertedImgs[$type] = $img->file_dst_path;
}
// Update the database
$data = array('storage_path' => $convertedImgs['original'], 'mime_type' => 'image/jpeg', 'extension' => 'jpg');
unset($convertedImgs['original']);
$data = array_merge($data, $convertedImgs);
if ($this->insert($key, $data) === false) {
// Delete the original image
$uploadedImg->clean();
// Delete the record in db
$this->delete($key);
// Log the error
Yii::log('Cannot resize the image ' . $data['storage_path'] . ' to ' . $path . '/' . $img->file_safe_name, 'error', 'application.modules.storage.Storage');
// Delete all converted images
unlink($data['storage_path']);
foreach ($convertedImgs as $imgType => $imgPath) {
unlink($imgPath);
}
// Return false
return false;
}
}
// Delete the temporary image
$uploadedImg->clean();
return $key;
}