2013-01-13 62 views
-1

xampp中的htdocs文件夾擁有777權限,我可以手動複製任何文件,但是上傳文件到子文件夾會產生錯誤。我的代碼是:我在本地xampp服務器上傳圖像時得到了權限被拒絕的錯誤

<?php 
define ('MAX_FILE_SIZE', 1024 * 50); 
if (array_key_exists('submit', $_POST)) { 
// define constant for upload folder 
define('UPLOAD_DIR', '/opt/lampp/htdocs/properties/'); 
// replace any spaces in original filename with underscores 
$file = str_replace(' ', '_', $_FILES['image']['name']); 
// create an array of permitted MIME types 
$permitted = array('image/gif', 'image/jpeg', 'image/pjpeg','image/png'); 
// upload if file is OK 
if (in_array($_FILES['image']['type'], $permitted) 
    && $_FILES['image']['size'] > 0 
    && $_FILES['image']['size'] <= MAX_FILE_SIZE) { 
switch($_FILES['image']['error']) { 
    case 0: 
    // check if a file of the same name has been uploaded 
    if (!file_exists(UPLOAD_DIR . $file)) { 
// move the file to the upload folder and rename it 
$success = move_uploaded_file($_FILES['image']['tmp_name'], UPLOAD_DIR $file); 
} else { 
$result = 'A file of the same name already exists.'; 
} 
if ($success) { 
$result = "$file uploaded successfully."; 
} else { 
$result = "Error uploading $file. Please try again."; 
} 
break; 
case 3: 
case 6: 
case 7: 
case 8: 
$result = "Error uploading $file. Please try again."; 
break; 
case 4: 
$result = "You didn't select a file to be uploaded."; 
} 
} else { 
$result = "$file is either too big or not an image."; 
} 
} 
?> 

我得到的錯誤是:

Warning: move_uploaded_file(/opt/lampp/htdocs/properties/Cover.jpg): failed to open stream: Permission denied in /opt/lampp/htdocs/listprop.php on line 82 

回答

0

檢查safe_mode是你php.ini

如果只有XAMPP文件夾是可寫的,不幫助,你on需要子文件夾也是可寫的。

其次,只是要求

define('UPLOAD_DIR', '/opt/lampp/htdocs/properties/'); 

其中lampp是不是應該說是xampp?只是問(這也可能導致移動問題)

+0

lampp是什麼目錄名稱在磁盤上,多數民衆贊成在我是如何安裝它.. safe_mode關閉在php.ini中,和chmod應用於所有的子文件夾以及htdocs目錄.. – sagar

+0

也,upload_tmp_dir沒有定義,錯誤顯示它使用tmp,所以我設置tmp文件夾777權限,但仍然沒有運氣 – sagar

+0

和你的apache日誌說什麼? –

相關問題