2016-12-24 61 views
-1

我有這樣的一個頁面上:保存圖像到服務器,以獲得網址後

<form method="POST" action="getdata.php" enctype="multipart/form-data"> 
<input type="file" name="image"> 
<input type="submit" value="Upload"> 
</form> 

,這裏是訪問getdata.php

error_reporting(E_ALL); 
ini_set('display_errors', 1); 

require "connection.php"; 


//connect to database 
$file=$_FILES['image']['name']; 
$file_tmp=$_FILES['image']['tmp_name']; 


$path="Libraries\Pictures".$file; 

if(file_exists($path)) 
{ 
chmod($path,0755); 
    unlink($path); 
} 

if(move_uploaded_file($file_tmp,$path)) 
{ 
    echo "File uploaded succesfully"; 

} 
else { 
    echo "no"; 
} 

我得到這些錯誤:

Warning: move_uploaded_file(Libraries\Pictures2.png): failed to open stream: Permission denied 
Warning: move_uploaded_file(): Unable to move '/tmp/phpnAKn2A' to 'Libraries\Pictures2.png' 

我該如何解決這些問題,這樣的URL將被存儲在我的數據庫,以方便以後訪問

+0

'$ PATH = 「庫\圖片」 $檔案;'是(可能)這裏缺少一個斜槓,如果'Pictures'。是一個文件夾(看起來很可能),'$ path =「Libraries/Pictures /".$文件;'並確保該文件夾可以寫入。 –

+0

當我添加一個/我得到這個: 'Warning:move_uploaded_file(Libraries \ Pictures/2.png):無法打開流:沒有這樣的文件或目錄' – jasy

+0

當我做一個\斜槓,它給了我一個完整的代碼錯誤。 – jasy

回答

0

你想要圖像或圖像的網址?
你的代碼不會給你圖像和網址,如果你想保存URL,你需要一個數據庫來存儲它們,如果你想從url上傳圖像,這是另一個故事,你必須使用這兩個功能:

file_put_contents 
file_get_contents 

一些錯誤更正:

$path ='/Libraries/Pictures'; 
// without $file 
// in place of 
$path="Libraries\Pictures".$file; 

我希望我幫你

相關問題