作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 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/
我是一名优秀的程序员,十分优秀!