示例#1
0
 /**
  * 下载一个远程文件
  * @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;
 }
 /**
  * @static
  */
 function operateImage($source, $filename, $savedir, $upload, $bhv)
 {
     require_once R_P . 'require/imgfunc.php';
     if (!($img_size = GetImgSize($source, $upload['ext']))) {
         P_unlink($source);
         showUploadMsg('upload_content_error');
     }
     $thumbInfo = array();
     $ifthumb = 0;
     if ($upload['ext'] != 'swf') {
         if ($bhv->allowThumb() && $upload['ext'] != 'gif') {
             $thumbInfo = PwUpload::makeThumb($source, $bhv->getThumbInfo($filename, $savedir), $bhv->ifftp, $ifthumb);
         }
         $bhv->allowWaterMark() && PwUpload::waterMark($source, $upload['ext'], $img_size);
         $upload['type'] = 'img';
     }
     return array($thumbInfo, $ifthumb, $upload['type']);
 }