[英]php file upload when uploading two files
In php I have a file upload script like this 在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'));
}
}
here you can see I am uploading two files and moving them into directory. 在这里您可以看到我正在上传两个文件并将它们移到目录中。 But when I am doing this to move upload files it is showing error like
但是当我这样做来移动上传文件时,它显示错误,例如
Parse error: syntax error, unexpected ',' in line number 18(where I have used move_uploaded_file).
But when I am using only one file like this 但是当我只使用一个这样的文件时
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'));
}
}
it is doing fine. 很好。 So can someone kindly tell me how to solve this issue?
那么有人可以告诉我如何解决这个问题吗?
Change your mysql_query line to: 将您的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());
by the way, Your sql has SQL injection and please don't use mysql_* functions. 顺便说一句,您的SQL具有SQL注入功能,请不要使用mysql_ *函数。 use mysqli or PDO.
使用mysqli或PDO。
You're missing move_uploaded_file
after your &&
. &&
之后,您缺少move_uploaded_file
。 The line 线
if(move_uploaded_file($_FILES['file']['tmp_name'], $tmpName.$image_name) && ($_FILES['store_image']['tmp_name'], $tmpName.$store_image) ) {
should be 应该
if(move_uploaded_file($_FILES['file']['tmp_name'], $tmpName.$image_name) && move_uploaded_file($_FILES['store_image']['tmp_name'], $tmpName.$store_image_name) ) {
Also you had $store_image
, which should be $store_image_name
. 另外,您还有
$store_image
,应该是$store_image_name
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.