我创建了一个 upload.php 文件,该文件包含HTML表单和上传图像所需的PHP代码,并且我使用XAMPP本地主机:
htdocs/web2/assets/upload.php
我想将图像上传到同一目录中的文件夹upload
:
htdocs/web2/assets/uploads/
<?php
<form action="?" method="post" enctype="multipart/form-data">
<!--wrap input button as around pre-existing image -->
<?php
echo '<label class="profile_gallery_image_in"><input type="file" name="fileToUpload" id="fileToUpload" onchange="form.submit()"/><p class="label"></p><img class="myImg" src='.$image.' height="100%" width="100%" /></label>';
?>
</form>
<!-- Commence Photo Upload -->
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
将表单设置为在输入类型更改时自动提交。看来工作正常,正在提交表单。
但是,我没有上传任何实际图像,也没有任何错误。
我该如何解决这个问题?