[英]php form no file no upload
I'm making a BETA "video uploading site" but people can just press upload without uploading anything, and spam my database AND the video site, how can i make it only upload if there are a file attched 我正在创建一个测试版“视频上传站点”,但是人们可以按上传而不上传任何内容,并且对我的数据库和视频站点进行垃圾邮件处理,我如何才能使其仅在有文件附加的情况下上传
my code is: 我的代码是:
<?php
mysql_connect("ip","username","password");
mysql_select_db("database");
if(isset($_POST['submit']))
{
$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
move_uploaded_file($temp,"uploaded/".$name);
$url = "http://www.mysite.dk/videoer/uploaded/$name";
mysql_query("INSERT INTO `videos` VALUE ('','$name','$url')");
}
?>
<html>
<head>
<title>Upload din video | Se videoer</title>
</head>
<body>
<a href="videoes.php">Videoer</a>
<form action="index.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" name="submit" value="Upload!" />
</form>
<?php
if(isset($_POST['submit']))
{
echo "<br />".$name." Er blevet uploadet";
}
?>
</body>
</html>
You'll want to check PHP's $_FILES
object to ensure the user submitted data, not just check if the $_POST['submit']
variable is set. 您将要检查PHP的
$_FILES
对象以确保用户提交了数据,而不仅仅是检查$_POST['submit']
变量是否已设置。
http://www.php.net/manual/en/reserved.variables.files.php http://www.php.net/manual/zh/reserved.variables.files.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.