在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'));
}
}
它做得很好。那么有人可以告诉我如何解决这个问题吗?
答案 0 :(得分: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。
答案 1 :(得分: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
。