Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.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_Mysql - Fatal编程技术网

Php 多文件上传不保存

Php 多文件上传不保存,php,mysql,Php,Mysql,我已经试了好几天了,想把我的头绕在这个上面,但我就是不能让它工作。我是php新手,相信你们可以帮助我或指出我做错了什么 我有一个表单需要将文件上传到某个目录,尽管浏览器进度条显示文件正在上传,但它仍然没有保存在目录中,也没有在MySql的表字段中捕获 具有多个上载表单的文件: <table cellpadding="5" cellspacing="0"> <form action="includes/add.php" method="post" enctype="m

我已经试了好几天了,想把我的头绕在这个上面,但我就是不能让它工作。我是php新手,相信你们可以帮助我或指出我做错了什么

我有一个表单需要将文件上传到某个目录,尽管浏览器进度条显示文件正在上传,但它仍然没有保存在目录中,也没有在MySql的表字段中捕获

具有多个上载表单的文件:

     <table cellpadding="5" cellspacing="0">
 <form action="includes/add.php" method="post" enctype="multipart/form-data">

 <th>Ad Warnings Documents</th>
 <tr>
 <td>Warning File 1</td>
 <td><input type="file" name="warning1" /></td>

 </tr>
  <tr>
 <td>Warning File 2</td>
 <td><input type="file" name="warning2"  /></td>

 </tr>
  <tr>
 <td>Warning File 3</td>
 <td><input type="file" name="warning3" /></td>
 </tr>

  <tr><td><input type="submit"  value="add"></form></td></tr>
 </table>

 </div>


 </body>
 </html> 

广告警告文件
警告文件1
警告文件2
警告文件3
上载脚本:

            <?php
include 'core/init.php';
 // Connects to your Database 
include 'includes/overall/header.php';
error_reporting(1);

$connect_error = 'Sorry, we\'re experiencing connection problems.';
mysql_connect('localhost', 'username', 'password') or die($connect_error);
mysql_select_db('DB_Name') or die($connect_error);

  //This is the directory where images will be saved 
$target = "../files/empdocs/"; 
$target1 = $target . basename( $_FILES['warning1']['name']); 
$target2 = $target . basename( $_FILES['warning2']['name']);
$target3 = $target . basename( $_FILES['warning3']['name']);
 //This gets all the other information from the form 

 $warning1=mysql_real_escape_string($_FILES['warning1']['name']); 
 $warning2=mysql_real_escape_string($_FILES['warning2']['name']);
 $warning3=mysql_real_escape_string($_FILES['warning3']['name']); 


  //Writes the information to the database 
mysql_query("INSERT INTO ref_employees (`warning1`,`warning2`,`warning3`) 
VALUES ('$warning1', '$warning2', '$warning3')")  or die(mysql_error());
  //Writes the file to the server 
if (move_uploaded_file($_FILES['warning1']['tmp_name'], $target1))
echo "The file ". basename( $_FILES['warning1']['name']). " has been uploaded, and your information has been added to the directory"; 
if (move_uploaded_file($_FILES['warning2']['tmp_name'], $target2))
 echo "The file ". basename( $_FILES['warning2']['name']). " has been uploaded, and your information has been added to the directory"; 
if (move_uploaded_file($_FILES['warning3']['tmp_name'], $target3))
    echo "The file ". basename( $_FILES['warning3']['name']). " has been uploaded, and your information has been added to the directory";
 //Tells you if its all ok 

 else { 

 //Gives and error if its not 
 echo "Sorry, there was a problem uploading your file."; 

 }
 ?>

 <?php
include 'includes/overall/footer.php'; ?>

您尚未在SQL语句中指定列名称,并且值计数可能大于或小于列计数。我建议您从现在起为每个
INSERT
语法指定所有必需的列名称

mysql_query("INSERT INTO ref_employees (`col1`,`col2`,`col3`) 
VALUES ('$warning1', '$warning2', '$warning3')") ;

您的代码编写得不好,并且您的问题缺少信息。我认为你应该尝试包括上传过程的确切部分,因为现在你的代码中有不同的部分。我已经做了修改,希望这是你在表格中看到的。第一部分是表单,第二部分是上传文件add.phpFirst,您的
mysql_*
函数都不推荐使用,您应该使用mysqli或类似PDO的接口。第二,如果有任何错误或信息,你也应该写出来,因为现在我可以进行任何猜测。通过这种方式,社区可以帮助你。我对我的文件做了一些更改,并让它上载文件,尽管我收到了代码中指定的错误。。。“很抱歉,上载文件时出现问题。”日志文件未显示相关进程的任何错误。我想“echo抱歉”可能是因为不止一个字段?我似乎仍然没有捕获数据库中的文件名,但是…有两个可能的问题。对于数据库条目,您的查询可能有问题。编写
mysql\u查询(“插入ref\u员工值('$warning1','$warning2','$warning3'))或die(mysql\u error())
查看是否有任何错误。对于上载部件,每个文件都有一个错误字段。在警告用户上载失败的部分,您可以
echo
错误,如
echo$\u文件['warning1']['error']
。这将为该文件的错误打印一个数字,您可以参考PHP手册查找该错误的上下文。你应该检查一下你所有的文件字段。我非常感谢你帮我解决了这么一个小的愚蠢的错误。感谢you@MauriceBotha很乐意帮忙。