1

在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'));
      }
 }

在这里你可以看到我正在上传两个文件并将它们移动到目录中。但是,当我这样做以移动上传文件时,它会显示错误,例如

Parse error: syntax error, unexpected ',' in line number 18(where I have used 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'));
      }
 }

它做得很好。那么有人可以告诉我如何解决这个问题吗?

4

2 回答 2

0

将您的 mysql_query 行更改为:

mysql_query('INSERT INTO `'._DB_PREFIX_.'databasename` (`id`, `custom_pin_name`,`store_image_name`) values ('', '$custom_pin','$store_img_name')') or die(mysql_error());

顺便说一句,你的 sql 有 SQL 注入,请不要使用mysql_*函数。使用 mysqli 或 PDO。

于 2013-09-06T13:09:16.770 回答
0

你在你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

于 2013-09-06T13:11:50.170 回答