Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 上载脚本找不到目录_Php_File Upload_Xampp - Fatal编程技术网

Php 上载脚本找不到目录

Php 上载脚本找不到目录,php,file-upload,xampp,Php,File Upload,Xampp,这是我的上传脚本 <?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 requ

这是我的上传脚本

<?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
上,出现一个错误,说明目录不存在,但它存在。 我已经在我的主机上上传了脚本,但即使在那里我也得到了错误。。。 我的目录是这样的


如何修复此问题?

上述代码是否存在于adm\u download\u center\u process.php文件中,并且中心目录也存在于同一目录中???如果是,则删除“/”之前的“/”/center/downloads/”,即仅尝试使用“center/downloads/”–

您编写的
/dir/dir/…
,这意味着您希望使用(对于windows):
C:/dir/dir/…
和对于linux
/dir/dir/…
{{C-将当前的驱动器号放在那里,}}。这是所谓的绝对路径,您想使用的是相对路径,即从非给定位置开始的路径

所以你应该

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

什么将被转换为当前目录/center/downloads/的相对路径,并可供应用程序使用。

哪个目录不存在?您收到错误消息的目录是什么?子目录“downloads”在哪里,即您的路径是/center/downloads/i,我有所有目录,
/center/downloads/
/center/images/
但脚本找不到它们中的任何一个,上面的代码是否存在于adm\u download\u center\u process.php文件中,并且中心目录也存在于同一目录中???如果是,则删除“/”之前的“/”/center/downloads/”,即仅尝试使用“center/downloads/”@PankajGarg。这有效,请将此作为答案填写,以便接受:)