我一天的大部分时间都花在这个图像 uploader 上,在浏览和访问许多线程和论坛后,我找到了解决我的问题的几种解决方案,但是我现在处于这样的境地:如果我尝试不同的解决方案,其他东西坏了。
到目前为止我所得到的:
<form action="create.php" method="post" enctype="multipart/form-data">
Select File
<input type="file" name="upload">
<input type="submit" name="submit" value="Upload" />
<input type="text" name="title" placeholder="Title" />
<input type="text" name="description" placeholder="Description" />
<input type="text" name="category" placeholder="Category" />
</form>
<?php
$conn = new PDO ("mysql:host=localhost;dbname=project;", "root", "0612733771Aa");
完整的 PHP 在这里,无法确定格式
我遇到的主要错误是:
if (isset($_POST["submit"]) && isset($_FILES['upload'])) {
$image_size = getimagesize($_FILES['upload']['tmp_name']);
if ($image_size === FALSE) {
die("Unable to determine image type of uploaded file");
}
警告:getimagesize():第 29 行 C:\Apache24\htdocs\create.php 中的文件名不能为空 无法确定上传文件的图像类型
任何帮助将不胜感激!
最佳答案
您需要在所有图像验证之后在 php 文件末尾调用
if (move_uploaded_file($image, $any_custom_target_file_path)) {
echo "The file has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
此后,您可以将 $any_custom_target_file_path 保存在数据库中。一旦执行脚本,tmp 文件就会被删除,所以我们需要将其保存到某个位置。
关于php - 将图像上传到 MySQL,出现无数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43526971/