简单的PHP / HTML上传页面 - 没有文件正在保存 [英] Simple PHP/HTML upload page - no files are saving
本文介绍了简单的PHP / HTML上传页面 - 没有文件正在保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是HTML / PHP的新手,我试图创建一个简单的php文件上传页面。
我将它作为我的HTML
I'm new to HTML/PHP and I'm trying to create a simple php file upload page. I have this as my HTML
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
我有这个作为我的php:
I have this as my php:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = 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;
}
}
?>
我已将这两个文件上传到我的主机(000webhost)中的正确文件夹,但是当我检查我的/ uploads文件夹里没有东西。我已经授予我所有的文件读写和执行权限来尝试和调试它 - 我将在后面了解安全。
I've uploaded both of these to the correct folder in my host (000webhost), yet when I check in my /uploads folder nothing is there. I've granted all my files read write and execute permissions to try and debug it - I'll learn about security later.
任何帮助将不胜感激! p>
Any help would be greatly appreciated!
推荐答案
您必须添加以下代码片段:
You must add this snippet of code:
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
之后:
after that:
echo "File is an image - " . $check["mime"] . ".";
这篇关于简单的PHP / HTML上传页面 - 没有文件正在保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文