Html 没有PHP的简单HTML上传表单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16772230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple HTML upload form Without PHP
提问by Mrportal
I was wondering if it will b possible to Create a HTML upload form and it will be purely HTML without calling any other PHP language to validate it. for example, Normally to create a file upload form is this way. Create an Upload-File Form
我想知道是否可以创建一个 HTML 上传表单,它是纯 HTML 而不调用任何其他 PHP 语言来验证它。例如,通常创建文件上传表单是这种方式。 创建上传文件表单
Look at the following HTML form for uploading files:
查看以下用于上传文件的 HTML 表单:
<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
While the PHP script will do the rest..
而 PHP 脚本将完成其余的工作..
Create The Upload Script
创建上传脚本
The "upload_file.php" file contains the code for uploading a file: And it will look lyk dis
“upload_file.php”文件包含上传文件的代码:它看起来像 lyk dis
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
but i was wondering if it can be possible not to use a PHP script but only an HTML script for example
但我想知道是否可以不使用 PHP 脚本而只使用 HTML 脚本
<html>
<body>
<form action="upload_file.html" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
While maybe another html script will do the rest..
虽然也许另一个 html 脚本会完成剩下的工作..
I hope u guys can understand my question and give me a reply, Thanks
我希望你们能理解我的问题并给我答复,谢谢
回答by deceze
HTML doesn't "do" anything. You can create the formin HTML perfectly fine. But if nothing on the server is handling the upload, it's pointless. You need somethingserver-side that does something with the uploaded data; HTML cannot.
HTML 不“做”任何事情。您可以完美地以 HTML 格式创建表单。但是如果服务器上没有任何东西在处理上传,那就没有意义了。你需要一些服务器端来处理上传的数据;HTML 不能。
回答by Borniet
When a file is uploaded to the webserver via an HTML form, it is placed in a temp directory, with a temporary filename. You need a script of some sort (PHP, .jsp, Perl,...) to 'do' something with the file, like placing it in the correct directory with the correct filename. If you don't do this, the webserver will delete this file when the next url is called in your session.
当一个文件通过 HTML 表单上传到网络服务器时,它被放置在一个临时目录中,并带有一个临时文件名。您需要某种脚本(PHP、.jsp、Perl 等)来对文件“执行”某些操作,例如将其放置在具有正确文件名的正确目录中。如果您不这样做,则在会话中调用下一个 url 时,网络服务器将删除此文件。