本文整理汇总了PHP中PwUpload::operateAttach方法的典型用法代码示例。如果您正苦于以下问题:PHP PwUpload::operateAttach方法的具体用法?PHP PwUpload::operateAttach怎么用?PHP PwUpload::operateAttach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PwUpload
的用法示例。
在下文中一共展示了PwUpload::operateAttach方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: download
/**
* 下载一个远程文件
* @param string $url
*/
function download($url, $bhv)
{
if (!$url || !PwDownload::checkUrl($url)) {
return false;
}
$filetype = PwDownload::getFileExt($url);
$filename = PwDownload::getFileName($url);
if (!$filetype || !$filename) {
return false;
}
//文件类型判定
if (!$filetype || !isset($bhv->ftype[$filetype])) {
return false;
}
$fileContent = PwDownload::getContents($url);
//文件尺寸判定
$fileSize = strlen($fileContent);
if ($fileSize < 1 || $fileSize > $bhv->ftype[$filetype] * 1024) {
unset($fileContent, $fileSize);
return false;
}
//init
$array = array('id' => 0, 'attname' => 'download', 'name' => $filename, 'size' => intval($fileSize), 'type' => 'zip', 'ifthumb' => 0, 'fileuploadurl' => '', 'ext' => $filetype);
//保存
list($saveFilename, $saveDir) = $bhv->getFilePath($array);
$source = PwUpload::savePath($bhv->ifftp, $saveFilename, $saveDir);
$tmpname = tempnam(DOWNLOAD_TEMP_PATH, DOWNLOAD_FILE_PREFIX);
writeover($tmpname, $fileContent);
if (!PwDownload::downloadMove($tmpname, $source)) {
showUploadMsg('upload_error');
}
$array['fileuploadurl'] = $saveDir . $saveFilename;
PwUpload::operateAttach($source, $saveFilename, $saveDir, $array, $bhv);
return $array;
}
示例2: add
function add($attach)
{
$upload = array('attname' => 'attachment', 'id' => intval($attach['aid']), 'name' => $attach['name'], 'size' => $attach['size'], 'type' => 'zip', 'ifthumb' => 0, 'fileuploadurl' => '');
$upload['ext'] = strtolower(substr(strrchr($attach['attachurl'], '.'), 1));
if (empty($upload['ext']) || !isset($this->bhv->ftype[$upload['ext']])) {
return false;
}
if ($upload['size'] < 1 || $upload['size'] > $this->bhv->ftype[$upload['ext']] * 1024) {
return false;
}
$dir = dirname($attach['attachurl']);
$dir && ($dir .= '/');
$srcfile = PwUpload::savePath($this->bhv->ifftp, basename($attach['attachurl']), $dir);
if (!file_exists($srcfile)) {
if ($this->bhv->ifftp) {
$ftp =& PwUpload::getFtpObj();
PwUpload::createFolder(dirname($srcfile));
if (!$ftp->get($srcfile, $attach['attachurl'])) {
return false;
}
} else {
return false;
}
}
list($filename, $savedir) = $this->bhv->getFilePath($upload);
$source = PwUpload::savePath($this->bhv->ifftp, $filename, $savedir);
PwUpload::createFolder(dirname($source));
if (!copy($srcfile, $source)) {
return false;
}
$upload['fileuploadurl'] = $savedir . $filename;
PwUpload::operateAttach($source, $filename, $savedir, $upload, $this->bhv);
$this->upload[] = $upload;
return true;
}
示例3: upload
function upload(&$bhv)
{
$uploaddb = array();
foreach ($_FILES as $key => $value) {
if (!PwUpload::if_uploaded_file($value['tmp_name']) || !$bhv->allowType($key)) {
continue;
}
$atc_attachment = $value['tmp_name'];
$upload = PwUpload::initCurrUpload($key, $value);
if (empty($upload['ext']) || !isset($bhv->ftype[$upload['ext']])) {
showUploadMsg('upload_type_error');
}
if ($upload['size'] < 1 || $upload['size'] > $bhv->ftype[$upload['ext']] * 1024) {
$GLOBALS['atc_attachment_name'] = $upload['name'];
$GLOBALS['oversize'] = $bhv->ftype[$upload['ext']];
showUploadMsg($upload['size'] < 1 ? 'upload_size_0' : 'upload_size_error');
}
list($filename, $savedir) = $bhv->getFilePath($upload);
$source = PwUpload::savePath($bhv->ifftp, $filename, $savedir);
if (!PwUpload::postupload($atc_attachment, $source)) {
showUploadMsg('upload_error');
}
clearstatcache();
$upload['size'] = ceil(filesize($source) / 1024);
$upload['fileuploadurl'] = $savedir . $filename;
PwUpload::operateAttach($source, $filename, $savedir, $upload, $bhv);
$uploaddb[] = $upload;
}
return $bhv->update($uploaddb);
}
示例4: upload
function upload(&$bhv)
{
$uploaddb = array();
$count = $size = 0;
foreach ($_FILES as $key => $value) {
if (!PwUpload::if_uploaded_file($value['tmp_name']) || !$bhv->allowType($key)) {
continue;
}
$atc_attachment = $value['tmp_name'];
$upload = PwUpload::initCurrUpload($key, $value);
if (empty($upload['ext']) || !isset($bhv->ftype[$upload['ext']])) {
$errCode = '上传附件类型错误!';
return $errCode;
}
if ($upload['size'] < 1 || $upload['size'] > $bhv->ftype[$upload['ext']] * 1024) {
$GLOBALS['atc_attachment_name'] = $upload['name'];
$GLOBALS['oversize'] = $bhv->ftype[$upload['ext']];
$errCode = '上传附件太小或超出' . $bhv->ftype[$upload['ext']] . 'KB!';
return $errCode;
}
list($filename, $savedir) = $bhv->getFilePath($upload);
$source = PwUpload::savePath($bhv->ifftp, $filename, $savedir);
if (!PwUpload::postupload($atc_attachment, $source)) {
$errCode = '上传附件出错';
return $errCode;
}
clearstatcache();
$upload['size'] = ceil(filesize($source) / 1024);
$upload['fileuploadurl'] = $savedir . $filename;
PwUpload::operateAttach($source, $filename, $savedir, $upload, $bhv);
$count++;
$size += $upload['size'] * 1024;
$uploaddb[] = $upload;
}
$bhv->update($uploaddb);
return 'success';
}