无法上传文件 - php& MySQL的

时间:2016-11-22 09:48:58

标签: php mysql notifications

我确实尝试将文件上传到系统中。它确实通过了上传到系统的所有必要条件。但是文件仍然没有上传到它。

这是我发现错误的精确位置。

由于系统仅使用给定的输出

进行阅读
  

系统正忙。请稍后再试一次

if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
        //echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
    } else {
        $msg = 'System is busy. Please try again laterb';
        goto ERROR;
    }

以下代码是对系统上电子邮件帖子的完整解析。

$email_params = array('fromEmail' => $_SESSION['user']['usr_id'], 'toEmail' => $to, 'subject' => $_POST['subject'], 'message' => $_POST['description'], 'addCC' => $cc);
$email = sendmail($email_params, 2);

if (!$email) {
    $msg = 'Failed to send email.';
     goto ERROR;
}

// Begin Upload FIle
$msg = "System is busy. Please try again later!";
$target_dir = "./images/ticket_attachments/";
$temp = explode(".", $_FILES["file"]["name"]);
$newfilename = round(microtime(true)) . '.' . end($temp);
$target_file = $target_dir . $newfilename;
$uploadOk = 1;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);

if ($imageFileType != '') {
    // Check if image file is a actual image or fake image
    if (isset($_POST["submit"])) {
        $check = getimagesize($_FILES["file"]["tmp_name"]);
        if ($check !== false) {
            echo "File is an image - " . $check["mime"] . ".";
            $uploadOk = 1;
        } else {
            $uploadOk = 0;
            $msg = 'File is not an image';
            goto ERROR;
        }
    }

    // Check if file already exists
    if (file_exists($target_file)) {
        $uploadOk = 0;
        $msg = 'Sorry, file already exists';
        goto ERROR;
    }

    // Check file size
    if ($_FILES["file"]["size"] > 500000) {
        $uploadOk = 0;
        $msg = 'Sorry, your file is too large. Your file must be less than 500KB';
        goto ERROR;
    }

    //  Allow certain file formats
    if ($imageFileType != "png" && $imageFileType != "jpg" && $imageFileType != "jpeg" && $imageFileType != "txt" && $imageFileType != "doc" && $imageFileType != "docx" && $imageFileType != "xml" && $imageFileType != "pptx" && $imageFileType != "gif" && $imageFileType != "ppt" && $imageFileType != "xps" && $imageFileType != "pptm" && $imageFileType != "zip" && $imageFileType != "csv" && $imageFileType != "xlsx" && $imageFileType != "xls" && $imageFileType != "rar" && $imageFileType != "mp4") {
        $uploadOk = 0;
        $msg = 'Sorry, files not supported. Only jpg, jpeg, png, docx, pdf, zip, xlsx files are supported.';
        goto ERROR;
    }

    if ($uploadOk == 0) {
        $msg = 'System is busy. Please try again latera';
        goto ERROR;
        // if everything is ok, try to upload file
    } else {
        $temp = explode(".", $_FILES["file"]["name"]);
        $newfilename = round(microtime(true)) . '.' . end($temp);
        if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
            //echo "The file ". basename( $_FILES["image"]["name"]). " has been uploaded.";
        } else {
            $msg = 'System is busy. Please try again laterb';
            goto ERROR;
        }
    }
} else {

    $newfilename = '';
}

请帮忙。感谢。

1 个答案:

答案 0 :(得分:1)

PHP可以访问上传文件夹(例如./images/ticket_attachments/)。

如果您在Linux上运行:chmod -R 777 ./images/

在Windows上:文件夹属性 - >安全 - >每个人/编辑 - >给予每个人完全控制权