【发布时间】:2021-07-25 08:08:55
【问题描述】:
所以,我正在尝试使用 move_uploaded_file() 上传图像。代码如下:
HTML 表单:
<form method="post" action="?page=prod&action=register" enctype="multipart/form-data">
<fieldset class="field-prods">
<label>Name:</label> <br>
<input type="text" name="txtName">
</fieldset>
<fieldset class="field-prods">
<label>Price:</label> <br>
<input type="number" name="nmbPrice">
</fieldset>
<fieldset class="field-prods">
<label>Image:</label> <br>
<input type="file" name="fileImage">
</fieldset>
<button type="submit" class="btn-prods">Register</button>
</form>
PHP 脚本:
if ($_POST != null) {
if (!empty($_POST['txtName']) && !empty($_FILES['fileImage']) && !empty($_POST['nmbPrice'])) {
Product::insert($_POST['txtName'], $_FILES['fileImage'], $_POST['nmbPrice']);
$target = "img/prods/" . $_FILES['fileImage']['name'];
$fileTmpName = $_FILES['fileImage']['tmp_name'];
move_uploaded_file($fileTmpName, $target);
}
}
但我收到了很多警告:
*Warning: Array to string conversion*
*Warning: move_uploaded_file(img/prods/livraria-print1.jpg): Failed to open stream: No such file or directory*
*Warning: move_uploaded_file(): Unable to move "F:\Programs\Xampp\tmp\php7CE5.tmp" to "img/prods/livraria-print1.jpg"*
有人可以帮我吗?
【问题讨论】:
-
那些是 warnings ,这与 error ... 不同
-
除此之外:信息非常清楚,那么您的实际问题是什么?
-
@arkascha 图像不会进入文件夹...我需要一些帮助
-
我们理解这一点,因为那是你写的。但是你得到的信息在这里很清楚:临时文件或命运文件夹不存在。这是我们无法改变的。你需要检查并修复它。
标签: php image file-upload