本文整理汇总了PHP中PwUpload::filterFileName方法的典型用法代码示例。如果您正苦于以下问题:PHP PwUpload::filterFileName方法的具体用法?PHP PwUpload::filterFileName怎么用?PHP PwUpload::filterFileName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PwUpload
的用法示例。
在下文中一共展示了PwUpload::filterFileName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: downloadThirdPlatformAvatar
protected function downloadThirdPlatformAvatar($uid, $avatar_url)
{
Wind::import('WSRV:base.WindidUtility');
$image_content = WindidUtility::buildRequest($avatar_url, array(), true, 2, 'get');
if ($image_content) {
$temp_file = tempnam(PUBLIC_PATH . "data/tmp/", 'tmp_');
$handle = fopen($temp_file, "w");
if ($handle) {
$res = fwrite($handle, $image_content);
fclose($handle);
Wind::import('WSRV:upload.action.WindidAvatarUpload');
Wind::import('LIB:upload.PwUpload');
$bhv = new WindidAvatarUpload($uid);
$upload = new PwUpload($bhv);
$value = array('name' => 'avatar.jpg', 'size' => 1024 * 1024 * 1, 'tmp_name' => $temp_file);
$file = new PwUploadFile('_0', $value);
$file->filename = $upload->filterFileName($bhv->getSaveName($file));
$file->savedir = $bhv->getSaveDir($file);
$file->store = Wind::getComponent($bhv->isLocal ? 'localStorage' : 'storage');
$file->source = str_replace('attachment', 'windid/attachment', $file->store->getAbsolutePath($file->filename, $file->savedir));
if (PwUpload::moveUploadedFile($value['tmp_name'], $file->source)) {
$image = new PwImage($file->source);
if ($bhv->allowThumb()) {
$thumbInfo = $bhv->getThumbInfo($file->filename, $file->savedir);
foreach ($thumbInfo as $key => $value) {
$thumburl = $file->store->getAbsolutePath($value[0], $value[1]);
$thumburl = str_replace('attachment', 'windid/attachment', $thumburl);
$result = $image->makeThumb($thumburl, $value[2], $value[3], $quality, $value[4], $value[5]);
if ($result === true && $image->filename != $thumburl) {
$ts = $image->getThumb();
}
}
}
}
@unlink($temp_file);
}
}
}
示例2: doAvatarAction
/**
* 修改头像
* @access public
* @return void
* @example
<pre>
/index.php?m=native&c=user&a=doAvatar <br>
post: securityKey <br>
postdata: Filename <br>
curl -X POST -F 'Filename=@icon1.jpg' -F 'csrf_token=aaa' -F '_json=1' -F 'securityKey=xx' -b 'csrf_token=aaa' '/index.php?m=native&c=user&a=doAvatar'
</pre>
*/
public function doAvatarAction()
{
$this->checkUserSessionValid();
//
Wind::import('WSRV:upload.action.WindidAvatarUpload');
Wind::import('LIB:upload.PwUpload');
$bhv = new WindidAvatarUpload($this->uid);
$upload = new PwUpload($bhv);
if (($result = $upload->check()) === true) {
foreach ($_FILES as $key => $value) {
if (!PwUpload::isUploadedFile($value['tmp_name']) || !$bhv->allowType($key)) {
continue;
}
}
$file = new PwUploadFile($key, $value);
if (($result = $upload->checkFile($file)) !== true) {
$this->showError($result->getError());
}
$file->filename = $upload->filterFileName($bhv->getSaveName($file));
$file->savedir = $bhv->getSaveDir($file);
$file->store = Wind::getComponent($bhv->isLocal ? 'localStorage' : 'storage');
$file->source = str_replace('attachment', 'windid/attachment', $file->store->getAbsolutePath($file->filename, $file->savedir));
//
if (!PwUpload::moveUploadedFile($value['tmp_name'], $file->source)) {
$this->showError('upload.fail');
}
$image = new PwImage($file->source);
if ($bhv->allowThumb()) {
$thumbInfo = $bhv->getThumbInfo($file->filename, $file->savedir);
foreach ($thumbInfo as $key => $value) {
$thumburl = $file->store->getAbsolutePath($value[0], $value[1]);
$thumburl = str_replace('attachment', 'windid/attachment', $thumburl);
//
$result = $image->makeThumb($thumburl, $value[2], $value[3], $quality, $value[4], $value[5]);
if ($result === true && $image->filename != $thumburl) {
$ts = $image->getThumb();
}
}
}
$this->showMessage('success');
}
$this->showMessage('operate.fail');
}