上传两个文件时上传php文件

标签 php mysql file-upload

在 php 中我有一个这样的文件上传脚本

<form id="formID" method="post" action="'.$_SERVER['REQUEST_URI'].'" enctype="multipart/form-data">
<div>
  <label>'.$this->l('Upload Your Custom Pin').'</label>
  <input type="file" name="file" id="file" />
</div>
<div>
  <label>'.$this->l('Upload Your Store Image').'</label>
  <input type="file" name="store_image" id="store_image" />
</div> 
<input type="submit" name="submit" value="submit" />
</form>          



$image_name = time().$_FILES['file']['name'];
  $store_image_name = time().$_FILES['store_image']['name'];

if(isset($_POST['submit'])) {
  mysql_query('INSERT INTO `'._DB_PREFIX_.'databasename` (`id`, `custom_pin_name`,`store_image_name`) values ('', $custom_pin,$store_img_name) or die(mysql_error());
   if(move_uploaded_file($_FILES['file']['tmp_name'], $tmpName.$image_name) && ($_FILES['store_image']['tmp_name'], $tmpName.$store_image) ) {
        $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully'));
      } else {
         $errors .= $this->displayError($this->l('You Have Some Errors'));
      }
 }

在这里您可以看到我正在上传两个文件并将它们移动到目录中。但是当我这样做来移动上传文件时,它会显示类似

的错误

解析错误:第 18 行(我使用 move_uploaded_file 的地方)出现语法错误、意外的“,”。

但是当我像这样只使用一个文件时

 if(isset($_POST['submit'])) {
  mysql_query('INSERT INTO `'._DB_PREFIX_.'databasename` (`id`, `custom_pin_name`,`store_image_name`) values ('', $custom_pin,$store_img_name) or die(mysql_error());
   if(move_uploaded_file($_FILES['file']['tmp_name'], $tmpName.$image_name) ) {
        $this->_html .=$this->displayConfirmation($this->l('Settings updated successfully'));
      } else {
         $errors .= $this->displayError($this->l('You Have Some Errors'));
      }
 }

一切顺利。那么有人可以告诉我如何解决这个问题吗?

最佳答案

您在 && 之后缺少 move_uploaded_file。线路

if(move_uploaded_file($_FILES['file']['tmp_name'], $tmpName.$image_name) && ($_FILES['store_image']['tmp_name'], $tmpName.$store_image) ) {

应该是

if(move_uploaded_file($_FILES['file']['tmp_name'], $tmpName.$image_name) && move_uploaded_file($_FILES['store_image']['tmp_name'], $tmpName.$store_image_name) ) {

您还有 $store_image,它应该是 $store_image_name

关于上传两个文件时上传php文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18658620/

相关文章:

尝试在 ByetHost 上从 VistaPanel 使用 phpMyAdmin 时出现 phpMyAdmin 无限循环

php - 在mysql查询中插入文件大小列

php - Blueimp jQuery 文件上传与数据库集成

javascript - Struts2上传多个文件前如何显示选中的文件名?

php - 如何识别 referrer 是否是 301 重定向

php - 无法在 AngularJS 和 PHP 中发布(错误 404)

php - mysql如果没有记录如何返回NULL值

MySQL INSERT 使用 SELECT 字段随着每个插入的行而递增

mysql - 一对多连接,多张表sql

php - 带有 ACL 的 MySQL DB 的 Rest 接口(interface)