2014-03-26 44 views
1

圖像使用工具移動到文件夾move()... 但是,當我想在html中顯示它時顯示我的完整路徑... 例如在檢查元素上顯示:/ opt/LAMPP/htdocs中/應用程序/上傳/ 開發我的應用程序在本地主機上Laravel圖像路徑

$destinationPath = 'uploads/'; 
$filename = Input::file('file')->getClientOriginalName(); 
Input::file('file')->move($destinationPath, $filename); 

回答

0

請記住只有「公開」目錄實際上是通過Web訪問,所以如果你是移動的東西什麼不是「公共」,然後它不會被網絡訪問。你可以通過以下方法來解決這個問題:a)將它移動到你的'public'目錄的某個地方,然後建立一個URL(我建議URL :: to('/ path/to/your/file')),或者你可以建立一個簡單地吐出你的文件的控制器功能。

我已經做了類似的東西在我的應用程序,以授予訪問權限(僅適用於授權用戶)控制器,查看下應用/用戶文檔文件夾中上傳的內容:

// Read file then spit it out 
$filepath = $doc->file; 
$imagecontents = File::get(app_path().'/userdocs/' . $filepath); 

if ($ext == "jpg" || $ext == "jpeg" || $ext == "png" || $ext == "gif") 
{ 
    $contentType = "image/$ext"; 
} 
else 
{ 
    $contentType = "application/octet-stream"; 
} 

return Response::make($imagecontents, 200, array('Content-Type' => $contentType));