Php 移动上传的文件不写入服务器,也不返回任何内容

Php 移动上传的文件不写入服务器,也不返回任何内容,php,html,forms,file-upload,fwrite,Php,Html,Forms,File Upload,Fwrite,我正在尝试将一个文件以及一些文本字段从HTML表单存储到我的web服务器。文本写得非常好,但是图像没有任何变化。我已经检查了错误,没有一个出现。电子邮件中也会收到该图像。 我相信权限也很好-它们在/img/gallery/和/img/gallery/data/上完全相同 以下是我的PHP表单: <?php include 'loadImages.php'; require_once('class.phpmailer.php'); $name = $_POST['name']; $emai

我正在尝试将一个文件以及一些文本字段从HTML表单存储到我的web服务器。文本写得非常好,但是图像没有任何变化。我已经检查了错误,没有一个出现。电子邮件中也会收到该图像。 我相信权限也很好-它们在
/img/gallery/
/img/gallery/data/
上完全相同

以下是我的PHP表单:

<?php
include 'loadImages.php';
require_once('class.phpmailer.php');

$name = $_POST['name'];
$email = $_POST['email'];
$location = $_POST['location'];
$desc = $_POST['desc'];

/**
 * PHPMailer simple file upload and send example
 */
$msg = '';
if (array_key_exists('userfile', $_FILES)) {
    // First handle the upload
    // Don't trust provided filename - same goes for MIME types
    // See http://php.net/manual/en/features.file-upload.php#114004 for more thorough upload validation
    $uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
        // Upload handled successfully
        // Now create a message
        // This should be somewhere in your include_path
        require 'PHPMailerAutoload.php';
        $mail = new PHPMailer;
        $mail->setFrom('gallery@####.co.uk', 'Website');
        $mail->addAddress('gallery@####.co.uk');
        $mail->Subject = 'Image Submission Recieved';
        $mail->msgHTML("<b>Name</b>: $name<br><b>Email</b>: $email<br><b>Location</b>: $location<br><b>Description</b>: $desc");
        // Attach the uploaded file
        $mail->addAttachment($uploadfile, 'Image');
        if (!$mail->send()) {
            $msg = "Mailer Error: " . $mail->ErrorInfo;
        } else {
            $msg = "Your message has been sent.";
        }
    } else {
        $msg = 'Failed to move file to ' . $uploadfile;
    }

    $date = date('Y-m-d_H-i-s');

    $path = $_SERVER['DOCUMENT_ROOT'].'/img/gallery/data/';
    $filename = $date.".txt";

    $file = fopen($path.$filename, "w") or die("Something went wrong storing your photo information");
      fwrite($file, $name . "\n");
      fwrite($file, $location . "\n");
      fwrite($file, $desc . "\n");
      fwrite($file, $email . "\n");
      fwrite($file, "Valid: False");
    fclose($file);

    $name = $_FILES['userfile']['name'];
    $path = $_SERVER['DOCUMENT_ROOT'].'/img/gallery/';
    $filename = $date . "." . pathinfo($name, PATHINFO_EXTENSION);

    $target = $path . $filename;
    echo $target;

    echo move_uploaded_file( $_FILES['userfile']['tmp_name'], $target);
}

$images = loadImages();
$imageData = LoadImageData();
?>
如果您需要查看其他内容,我将上载。

$date = date('Y-m-d_H-i-s');

$path = $_SERVER['DOCUMENT_ROOT'].'/img/gallery/data/';
$filename = $date.".txt";

$file = fopen($path.$filename, "w") or die("Something went wrong storing your photo information");
  fwrite($file, $name . "\n");
  fwrite($file, $location . "\n");
  fwrite($file, $desc . "\n");
  fwrite($file, $email . "\n");
  fwrite($file, "Valid: False");
fclose($file);

$name = $_FILES['userfile']['name'];
$path = $_SERVER['DOCUMENT_ROOT'].'/img/gallery/';
$filename = $date . "." . pathinfo($name, PATHINFO_EXTENSION);

$target = $path . $filename;
echo $target;

echo move_uploaded_file( $_FILES['userfile']['tmp_name'], $target);
在这个代码之上

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

然后再试一次。

您正在将它保存到/tmp目录中,我认为当脚本退出时,它会被清除。尝试保存到另一个目录。

您在错误日志中看到了什么错误?您可以发布打印($文件)的输出吗?@skrilled我没有收到任何错误。@Jaime正在更新它。我现在得到
无法将文件移到/temp/74ed5209e101d58611901d2b7d518cc1162a08e5hfbbe
图像实际上正在上载,尽管有这个错误,我相信这是因为我上传了两次。我真傻。我把第18行改成了
$uploadfile=tempnam($\u SERVER['DOCUMENT\u ROOT']./img/gallery/temp/”,sha1($\u FILES['userfile']['name'])但仍然会得到相同的结果。这就是你的意思吗?
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {