public function upload(){
$url = "https://oss.aiqu.com/data/upload/game/20190226/5c7528c5d8df6.png";
$apifile = ROOTPATH.'api/game/sdk.php';
if (!is_file($apifile)) {
return dr_return_data(0, dr_lang('接口文件不存在'));
}
require $apifile;
print_r($sdk->upload($url,"測試-small".time()));
}
/**
*遠(yuǎn)程圖片本地化
*@param string $img_url 圖片地址
*@return int 歸檔id
*/
public function upload($img_url,$title){
$rt = \Phpcmf\Service::L('upload')->down_file([
'url' => $img_url,
'attachment' => \Phpcmf\Service::M('attachment')->get_attach_info(1), // 0值不屬于存儲策略,填寫策略ID號表示附件存儲策略,可以是遠(yuǎn)程存儲,可以是本地存儲,如果不用存儲策略就填0
]);
if ($rt['code']) {
// 附件歸檔 可選
$att = \Phpcmf\Service::M('attachment')->save_data($rt['data'], $title);
if ($att['code']) {
return $att['code'];
}else{
return $att;
}
} else {
return $rt;
}
}提示:Array ( [code] => 0 [msg] => 遠(yuǎn)程獲取的圖片不是一張可用的圖片 [data] => Array ( ) );
有哪位大佬知道原因嗎?
說明圖片無法通過php程序下載,換一張圖片、換一個(gè)url的圖片,試一試,排除法是不是圖片文件問題還是圖片服務(wù)器的問題
config/rewrite.php
<?ph $rule ="tag-".$get.name."-[page].html"; ?>
{related module=$c.dirname tag=$tag.tags page=1 pagesize=10 urlrule=$rule}
你這個(gè)循環(huán)體里面分頁啊,我覺得不現(xiàn)實(shí),因?yàn)橐粋€(gè)頁面只能有一個(gè)分頁標(biāo)簽
回復(fù)@易學(xué)習(xí) 換了圖片 也提示一樣,還有二樓是回復(fù)錯(cuò)了么
回復(fù)錯(cuò)了,我本地運(yùn)行你的代碼可以下載啊
/** * 下載文件 */ public function down_file($config) { /* $client = \Config\Services::curlrequest(); $res = $client->get($config['url'], [ 'timeout' => (int)$config['timeout'], ]); if ($res->getStatusCode() == 200) { $data = $res->getBody(); } else { log_message('error', '服務(wù)器無法下載文件:'.$config['url']); return dr_return_data(0, dr_lang('文件下載失敗')); }*/ $data = dr_catcher_data($config['url'], (int)$config['timeout']); if (!$data) { log_message('error', '服務(wù)器無法下載文件:'.$config['url']); return dr_return_data(0, dr_lang('文件下載失敗')); } $name = substr(md5(SYS_TIME.uniqid().$config['url']), rand(0, 20), 15); // 隨機(jī)新名字 $file_ext = $this->_file_ext($config['url']); // 擴(kuò)展名 // 安全驗(yàn)證 $rt = $this->_safe_check($file_ext, $data); if (!$rt['code']) { return dr_return_data(0, $rt['msg']); } $file_name = $this->_file_name($config['url']); // 文件實(shí)際名字 if (!$file_ext) { log_message('error', '無法獲取文件擴(kuò)展名:'.$config['url']); return dr_return_data(0, dr_lang('無法獲取文件擴(kuò)展名')); } // 保存目錄名稱 $path = isset($config['path']) && $config['path'] ? $config['path'].'/' : date('Ym', SYS_TIME).'/'; $file_path = $path.$name.'.'.$file_ext; // 開始上傳存儲文件 $rt = $this->save_file('content', $data, $file_path, $config['attachment'], (int)$config['watermark']); if (!$rt['code']) { return dr_return_data(0, $rt['msg']); } // 上傳成功 $url = $config['attachment']['url'].$file_path; // 如果是圖片先獲取圖片尺寸 $info = []; if (in_array($file_ext, ['jpg', 'jpeg', 'png', 'gif'])) { list($info['width'], $info['height']) = @getimagesize($config['attachment']['value']['path'].$file_path); // $img = getimagesize($config['attachment']['value']['path'].$file_path); // if (!$img) { // // 刪除文件 // // 按照附件存儲類型來保存文件 // $storage = new \Phpcmf\Library\Storage(); // $storage->delete($config['attachment'], $file_path); // return dr_return_data(0, dr_lang('遠(yuǎn)程獲取的圖片不是一張可用的圖片')); // } // $info = [ // 'width' => $img[0], // 'height' => $img[1], // ]; } // 文件預(yù)覽 $preview = dr_file_preview_html($url); return dr_return_data(1, 'ok', [ 'ext' => $file_ext, 'url' => $url, 'md5' => md5($data), 'file' => $file_path, 'size' => (int)$rt['data']['size'], 'path' => $config['attachment']['value']['path'].$file_path, 'name' => $file_name, 'info' => $info, 'remote' => $config['attachment']['id'], 'preview' => $preview, ]); }系統(tǒng)bug 結(jié)帖
我沒改過系統(tǒng),所以應(yīng)該不是系統(tǒng)bug,我可以直接使用,難道是你哪個(gè)php.ini沒有配置?
五元,能不能領(lǐng)呢,我確實(shí)運(yùn)行你的代碼沒有報(bào)錯(cuò)。。。
回復(fù)@易學(xué)習(xí) 交個(gè)朋友,是我這邊沒有更新代碼 這塊看git 已經(jīng)去掉我貼圖注釋那塊代碼了