2014-04-20 74 views
0

這是我上傳腳本上傳腳本沒有找到目錄

<?php 
include 'core/init.php'; 
protect_page(); 
admin_page(); 

$fields = array('title', 'description'); 
foreach($_POST as $key=>$value) { 
if(empty($value) && in_array($key, $fields) == true){ 
    $errors[] = 'All fields are required'; 
    break 1; 
} 
} 

if(!empty($errors)){ 
    echo output_errors($errors); 
} 
else{ 
#remove slashes from content 
$title = stripslashes($_POST["title"]); 
$description = stripslashes($_POST["description"]); 


if(isset($_FILES["FileInput"]) && isset($_FILES["image"]) && $_FILES["FileInput"]["error"]== UPLOAD_ERR_OK) 
{ 
    ############ Edit settings ############## 
    $UploadMainDirectory = '/center/downloads/'; 
    $UploadImageDirectory = '/center/images/'; 
    ########################################## 

    //check if this is an ajax request 
    if (!isset($_SERVER['HTTP_X_REQUESTED_WITH'])){ 
     die(); 
    } 

    if ($_FILES["FileInput"]["size"] > 1024*1024*1024) { 
     die("Main file size is too big!"); 
    } 

    if ($_FILES["image"]["size"] > 1*1024*1024) { 
     die("Image size is too big!"); 
    } 

    switch(strtolower($_FILES['FileInput']['type'])) 
    { 
     //allowed file types 
     case 'image/png': 
     case 'image/gif': 
     case 'image/jpeg': 
     case 'image/pjpeg': 
     case 'text/plain': 
     case 'application/x-zip-compressed': 
     case 'application/x-rar-compressed': 
     case 'application/octet-stream': 
     case 'application/zip': 
     case 'application/rar': 
     case 'application/x-zip': 
     case 'application/x-rar': 
      break; 
     default: 
      die('Unsupported main file!'); //output error 
    } 

    switch(strtolower($_FILES['image']['type'])) 
    { 
     //allowed file types 
     case 'image/png': 
     case 'image/gif': 
     case 'image/jpeg': 
     case 'image/pjpeg': 
      break; 
     default: 
      die('Unsupported image file!'); //output error 
    } 

    $File_Name   = strtolower($_FILES['FileInput']['name']); 
    $File_Ext   = substr($File_Name, strrpos($File_Name, '.')); //get file extention 
    $Random_Number  = rand(0, 9999999999); //Random number to be added to name. 
    $NewFileName  = $Random_Number.$File_Ext; //new file name 

    $ImageName   = strtolower($_FILES['image']['name']); 
    $ImageExt   = substr($ImageName, strrpos($ImageName, '.')); //get file extention 
    $NewImageName  = $Random_Number.$ImageExt; //new file name 

    if(move_uploaded_file($_FILES['FileInput']['tmp_name'], $UploadMainDirectory.$NewFileName) && move_uploaded_file($_FILES['image']['tmp_name'], $UploadImageDirectory.$NewImageName)) 
     { 
     $fields = array('type', 'name', 'description', 'file', 'image'); 

     $upload_data = array(
     'type'   => $_POST['type'], 
     'name'   => $_POST['title'], 
     'description' => $_POST['description'], 
     'file'   => $NewFileName, 
     'image'   => $NewImageName, 
     ); 
     array_walk($upload_data, 'array_sanitize'); 
     $fields = '`' . implode('`, `', array_keys($upload_data)) . '`'; 
     $data = '\'' . implode('\', \'', $upload_data) . '\''; 

     mysql_query("INSERT INTO `downloads` ($fields) VALUES ($data)"); 

     die('Success! File Uploaded.'); 
    }else{ 
     die('Error uploading Files!'); 
    } 

} 
else 
{ 
    die('Something went wrong!'); 
} 
} 
?> 

我的問題是,該腳本不工作,在localhost給我,說該目錄不存在的錯誤,但它的存在。 我已經上傳主機上的腳本,但即使在那裏我得到的錯誤... 我的目錄看起來像這樣

enter image description here

我怎樣才能解決這個問題?

+0

*哪個*目錄不存在?什麼是您收到錯誤信息的目錄? – hakre

+0

其中是子目錄「downloads」,即你的路徑是/ center/downloads/ –

+0

我擁有所有目錄,包括'/ center/downloads /'和'/ center/images /',但腳本沒有找到它們中的任何一個 – Paradox

回答

0

上述代碼是否存在於adm_download_center_process.php文件中,並且中心目錄也存在於同一目錄中?如果是的話,那麼在「/ center/downloads /」之前刪除「/」,即只用「center/downloads /」來嘗試 -

1

你寫了/dir/dir/....這意味着你想用(對於windows):C:/dir/dir/...和linux /dir/dir/... {{C - 把當前驅動器號的網站運行在}}。這是calles 絕對路徑你想要使用的是相對路徑你不是從給定位置開始的路徑。

所以,你應該有

############ Edit settings ############## 
$UploadMainDirectory = 'center/downloads/'; 
$UploadImageDirectory = 'center/images/'; 
########################################## 

什麼會被翻譯成相對路徑current_directory/center/downloads/並可以通過程序使用。