2011-11-07 39 views
0

我是PHP和Linux的新手。我在嘗試設置文件上載腳本時遇到問題。它停在!is_writable。我覺得這是服務器上的權限問題,但我已將所有設置設置爲777.我錯過了什麼嗎?PHP腳本和Ubuntu服務器權限問題

服務器是一個設置爲具有本地訪問權的虛擬機的Ubuntu服務器。從

ini_set('error_reporting', E_ALL); 
echo "<br/>"; 

//This gets all the other information from the form 
$name=$_POST['name']; 
$email=$_POST['email']; 
$phone=$_POST['phone']; 
$pic=($_FILES['photo']['name']); 

//This is the directory where images will be saved 
$target = "testimages/"; 
$allowed_filetypes = array('.jpg','.bmp','.png'); // These will be the types of file that will pass the validation. 
$target = $target . basename($_FILES['photo']['name']); 


$filename = $_FILES['photo']['name']; // Get the name of the file (including file extension). 
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. 

// Check if the filetype is allowed, if not DIE and inform the user. 
if(!in_array($ext,$allowed_filetypes)) 
die('The file you attempted to upload is not allowed.'); 

// Check if we can upload to the specified path, if not DIE and inform the user. 
if(!is_writable($target)) 
die('You cannot upload to the specified directory, please CHMOD it to 777.'); 

//Writes the photo to the server 
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) 
{ 

//Tells you if its all ok 
echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; 
} 
else { 

//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 

// Connects to your Database 
mysql_connect("localhost","phptestuser","ct6697") or die(mysql_error()) ; 
mysql_select_db("Testing") or die(mysql_error()) ; 

//Writes the information to the database 
mysql_query("INSERT INTO employees (name, email, phone, pic) VALUES ('$name', '$email', '$phone', '$pic')"); 

代碼嘗試以下兩個答案,仍不能正常使用,任何其他建議?從LS -al

上市:

drwxrwxrwx 9 root  root  4096 Nov 7 16:09 . 
drwxr-xr-x 14 root  root  4096 Nov 7 16:53 .. 
drwx------ 2 www-data www-data 4096 Nov 7 15:05 .gnupg 
-rwxrw-rw- 1 yoderman94 www-data 2464 Nov 8 07:31 Add.php 
-rwxrw-rw- 1 yoderman94 www-data 629 Nov 7 15:27 ImageUpload.php 
-rwxr--r-- 1 yoderman94 yoderman94 2115 Nov 7 15:45 PHP_Test.php 
drwxr-xr-x 2 yoderman94 yoderman94 4096 Nov 1 14:39 _mmServerScripts 
-rw-r--r-- 1 root  root  177 Oct 27 11:32 index.html 
-rw-rw-r-- 1 yoderman94 yoderman94 44 Nov 1 10:19 phpinfo.php 
drwxrwxrwx 2 www-data www-data 4096 Nov 7 16:09 testimages 
drwxrwxrwx 2 www-data www-data 4096 Nov 7 15:08 tmp 

回答

0

嘗試chown - 上傳文件夾的所有者更改,到Web服務器,它通常是www數據;

只需運行是這樣的:sudo chown www-data:www-data ./testimages/

,並嘗試使用絕對路徑上傳目錄。

0
$target = "testimages/"; 
if(!is_writable($target)) 

建議:嘗試設置$目標等於文件的絕對路徑,可能在/ var/WWW/testimages