[英]PHP convert '../folder/file.php' into url
所以我正在開發一個當前在localhost上的網站。 我正在測試圖像上傳器,我必須為要顯示的圖像生成一個URL。
etc etc..
// move the file to folder <- it works
move_uploaded_file($_FILES["file"]["tmp_name"], '../../common/img/post-uploads/' . $name);
// Generate response.
$response = new StdClass;
$response->link = MAINFOLDER . '/common/img/post-uploads/' . $name; // but I need an URL here..?:/
echo stripslashes(json_encode($response));
如您所見,當我將上傳的文件移動到路徑時,它就像這樣“../../common/img/post-uploads”
但最后,我想得到一個URL ..所以最終的圖像就像是
<img src =“http://localhost/mysite/common/image/post-uploads/image.jpg”>
有可能嗎? 喜歡
$response->link = convertThisToURL('../../common/img/post-uploads/' . $name);
? :/
由於你顯示兩個../
我認為這個項目在你的域之外。 除非完整鏈接在域目錄中,否則無法做到這一點。
根據你的評論,然后回答那將是一個符號鏈接。
ln -s /localhost/mysite/common/img/post-uploads /localhost/mysite/images
例如。 然后發布那個漂亮的新網址,沒有那些../的東西
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.