php上傳增加網域名稱
function ajaxfile() {
foreach (lib_request::$files as $filename => $value) {
$picname = lib_request::$files[$filename]['name'];
$picsize = lib_request::$files[$filename]['size'];
if ($picname != "") {
if ($picsize > 1024000) {
echo json_encode(array(
'code' => '-1',
'title' => '圖片上傳',
'msg' => '圖片大小不能超過1M'
));
exit();
}
$type = get_extension($picname);
if ($type != "gif" && $type != "jpg" && $type != "jpeg" && $type != "png") {
echo json_encode(array(
'code' => '-1',
'title' => '圖片上傳',
'msg' => '圖片格式不對!'
));
exit();
}
$upload_path = '/up';
$rand = rand(100, 999);
$pics = date("YmdHis") . $rand . '.' . $type;
$dir = date('/YmdH/');
$pic_path = $upload_path . $dir;
$pic_url = $pic_path . $pics;
if (!file_exists(PATH_ROOT . $pic_path)) {
creatFolder(PATH_ROOT . $pic_path);
}
$PATH_ROOT = PATH_ROOT . $pic_url;
move_uploaded_file(lib_request::$files[$filename]['tmp_name'], $pic_path);
if (request('type') == 'goods') {
makeThumbnail($pic_path, $pic_path . '_290x290.jpg', 290, 190);
}
}
$arr[$filename] = array(
'name' => $picname,
'pic' => $pic_url,
'size' => $picsize
);
}
echo json_encode($arr);
exit();
}
以上上傳後得到的路徑是/up/xxxxx/xxxxx.jpg
我想修改為:http://www.xxxx.com//up/xxxxx/xxxxx.jpg
------解決思路----------------------
估計是想得到一個改變的url ?
$pic_url = ‘http://www.xxxx.com/’.$pic_path . $pics;
是這樣嗎?提問說的不清晰 哈哈。
------解決思路----------------------
你說的是什麼意思??不是很明白
如果是資料庫裡面的路徑 你update就可以了
如果是上傳到其他伺服器的,這應該不行把