/** * 下载一个远程文件 * @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; }
/*} elseif ($type == 'cms') { require_once(R_P . 'mode/cms/lib/upload/articleupload.class.php'); $mutiupload = new articleMutiUpload($uid);*/ } elseif ($type && file_exists(R_P . "require/extents/attach/{$type}mutiupload.class.php")) { $class = $type . 'MutiUpload'; require_once S::escapePath(R_P . "require/extents/attach/{$type}mutiupload.class.php"); $mutiupload = new $class($uid); } else { L::loadClass('attmutiupload', 'upload', false); $mutiupload = new AttMutiUpload($uid, intval($_POST['fid'])); } if (($return = $mutiupload->check()) !== true) { showExtraMsg($return); } L::loadClass('download', '', false); $downloaded = PwDownload::getRemoteFiles($urls, $mutiupload); $attachs = $mutiupload->getAttachs(); //×é×°Êä³ö $tmpArray = array(); foreach ($urls as $k => $v) { if (isset($downloaded[$k])) { $attachInfo = array_shift($attachs); if ($attachInfo['attachurl']) { list($attachInfo['attachurl']) = geturl($attachInfo['attachurl'], 'lf', $attachInfo['ifthumb'] & 1); //list($attachInfo['attachurl']) = geturl($attachInfo['attachurl'], 'lf'); } $tmpArray[$attachInfo['aid']] = $attachInfo; } else { $tmpArray[] = array(); } }