2012-08-01 34 views
2

我一直在尋找一種將相對路徑放入到file_put_content()函數中的方法。基本上我想複製一個文件到我的服務器的目錄之一。這裏是我迄今所做的:在CakePHP的file_put_content()中指定相對路徑服務器

function curl($url){ 
      $ch = curl_init(); 
      curl_setopt($ch, CURLOPT_URL, $url); 
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
      $data = curl_exec($ch); 
      curl_close($ch); 
      return $data; 
     } 

     $image_new = curl($image); 
     file_put_contents("/minimaled_server_path/app/webroot/logo_url", 
          $image_new); 

它扔我的錯誤如下:

file_put_contents(/minimal_server_path/app/webroot/logo_url) 
    [function.file-put-contents]: 
failed to open stream: No such file or directory 
    [APP/Controller/AppsController.php, line 105] 

缺少什麼我在這裏?

+2

嘗試從文件路徑除去最主要的斜線。相對路徑不以斜槓開始,絕對路徑。另外,考慮使用'fopen()'並將句柄傳遞給'CURLOPT_FILE',它會更有效率。 – DaveRandom 2012-08-01 10:07:10

+0

我已經改變了我的代碼,正如你所說的。但仍然沒有得到解決 – 2012-08-01 10:10:22

+1

還是一樣的錯誤?試試'echo getcwd();'以確保你在你認爲你的目錄中工作。 – DaveRandom 2012-08-01 10:11:23

回答

0

嘗試使用真實路徑函數計算從文件的路徑,你執行的功能

file_put_contents(realpath("/../../minimaled_server_path/app/webroot/logo_url"), $image_new); 
+0

不適用於不存在的路徑! – user3292653 2014-05-10 15:12:43

相關問題