php - 无法将上传的文件移动到 php 中的在线服务器

标签 php mysql

我正在尝试上传文件并将文件作为附件发送,并下载带有附件的文件,以便将上传的文件移动到名为 temp 的文件夹中。我已经授予权限 chmod。但是文件无法移动到上传的文件夹。

这是代码

<html>
<head>
<title> Sending Email </title>
</head>
<body>
<?php
session_start();
// Read POST request params into global vars
include_once "db.php";

$name1=mysql_real_escape_string(stripslashes($_POST['name1']));
$subject1=mysql_real_escape_string(stripslashes($_POST['subject1']));
$email1=$_POST['email1'];
$phone=$_POST['phone'];
$username=mysql_real_escape_string($_SESSION['sess_user4']);
  $to = "checkformemail@gmail.com";
 $from=$_POST['email1'];
 $fileatt      = $_FILES['fileatt']['tmp_name'];
 $fileatt_type = $_FILES['fileatt']['type'];
 $fileatt_name = mysql_real_escape_string($_FILES['fileatt']['name']);
 $fileatt_size = $_FILES['fileatt']['size']; 
 $aa=filesize($fileatt);
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
  // Read the file to be attached ('rb' = read binary)
$name1=mysql_real_escape_string(stripslashes($_POST['name1']));
  $file = fopen($fileatt,'rw');
  $content = fread($file,filesize($fileatt));
 chmod("temp/", 0777); 
fclose($file);
$message="Name:$name1\n\n
          Email:$email1\n
          Subject:$subject1\n
          Phone No:$phone";
  // Generate a boundary string
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";


  // Add the headers for a file attachment
  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: multipart/mixed;\n" .
              " boundary=\"{$mime_boundary}\"";

  // Add a multipart boundary above the plain message
  $message = "This is a multi-part message in MIME format.\n\n" .
             "--{$mime_boundary}\n" .
             "Content-Type: text/html; charset=\"iso-8859-1\"\n" .
             "Content-Transfer-Encoding: 7bit\n\n" .
            stripslashes($message). "\n\n";

  // Base64 encode the file data
  $content = chunk_split(base64_encode($content));

  // Add file attachment to the message
  $message .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              //"Content-Disposition: attachment;\n" .
              //" filename=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
              $content . "\n\n" .
              "--{$mime_boundary}--\n";

}

// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
   echo "<script>window.open('display.php','_self')</script>";
} else {
  echo "<p>Mail could not be sent. Sorry!</p>";
}
move_uploaded_file($_FILES["fileatt"]["tmp_name"],'temp/'.basename($_FILES['fileatt']['name']));
$query = "INSERT INTO register (name,type,size,content,name1,email1,subject1,phone,username) VALUES ('$fileatt_name','$fileatt_type','$fileatt_size','$content','$name1','$email1','$subject1','$phone','$username')";

mysql_query($query) or die('Error, query failed');  
?>
</body>
</html>

最佳答案

尝试回显 $_FILES["fileatt"]["tmp_name"],'temp/'.basename($_FILES['fileatt']['name']));

看看你是否得到了预期的路径。

关于php - 无法将上传的文件移动到 php 中的在线服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38366843/

相关文章:

php动态类构建

php - 如何在 PHP 中使用 shell_script 创建数据库后创建表?

mysql - 如何显示数据库中的数据[MySQL查询]

php - 如何在php mysql查询中搜索where条件column_name ='bolt 1/2 inch'

php - 如何从 MySQL 数据库创建分页表?

php - 实体命名空间子类在 Doctrine 中不起作用

php - Zend getParam 多值

php - 未使用 PDO (MySQL) 处理排序方向 ASC/DESC

mysql - 通过比较 ENUM 和 SET 列来选择行的最佳方法是什么

php - for 循环只取 mysql 结果的第一个值