/** * 下载一个远程文件 * @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; }
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; }
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); }
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'; }