2011-11-07 3 views
0

첫 번째 질문은 PHP와 Linux에 익숙하지 않습니다. 파일 업로드 스크립트를 설정하는 데 문제가 있습니다. ! is_writable에서 멈 춥니 다. 나는이 서버에서 사용 권한 문제가있는 것처럼 느낀다 그러나 나는 모든 것을 777로 설정했습니다. 뭔가 놓친 건가요?PHP 스크립트 및 우분투 서버 권한 문제

서버는 로컬 액세스 권한이있는 가상 시스템으로 설정된 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 시도 - 업로드 폴더의 소유자 변경은 웹 서버로, 보통은 www가 데이터입니다;

는 같은 실행 sudo chown www-data:www-data ./testimages/

및 디렉토리를 업로드 절대 경로를 사용하려고합니다.

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

제안 : 파일의 절대 경로, 아마의/var/www /에서 testimages

동일한 $ 목표를 설정하십시오