我正在寻找一些帮助我的PHP脚本为我的网站,我正在教一小群学生,有人问,我们究竟是如何把它放在互联网上?所以我做了一个php上传脚本,以便他们可以上传到我的网站与他们的朋友分享。PHP防止上传文件的种类,删除上传文件中的空格
我有两个问题:
1)究竟我如何使它所以当有人上传了一个文件,它会删除所有的空间中上传的文件名? 2)我究竟如何做到这一点,我可以防止人们上传某些类型的文件? (如JPG文件,PNG文件EXT)
继承人我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content=
"width=device-width, initial-scale=1" />
<title>
File Upload
</title>
<link rel="icon" type="image/png" href="icons/favicon.png" />
<link href="css/bootstrap.min.css" rel="stylesheet" type=
"text/css" />
<script src="js/bootstrap.min.js" type="text/javascript"></script>
<script src="js/jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="js/bootstrap-filestyle.js" type="text/javascript"></script>
<script src=
"https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"
type="text/javascript"></script>
<script src=
"https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"
type="text/javascript"></script>
</head>
<body>
<div class="container" style=
"margin-top: 30px;margin-bottom: 30px">
<div class="row">
<div class="span12">
<h2 style="text-align: center;">
<strong>Alydus.net File Upload</strong>
</h2>
<div class="well">
<form role="form" enctype="multipart/form-data" method=
"post">
<h3>
Upload a file
</h3>
<hr />
<div class="row">
<div class="col-xs-6">
<div class="form-group">
<input type="file" name="example" id="input01"
class="filestyle" data-buttonbefore="true" />
<?php
$dir_upload = '/usr/local/nginx/html/upload/uploads/';
$max_size = 200000000;
$file = $_FILES['example'];
if ($file['size'] <= $max_size && $file['size'] > 0) {
$new_name = time() . '-' . $file['name'];
$copied = copy($file['tmp_name'], $dir_upload . $new_name);
if ($copied) {
print("Successfully uploaded to server, you can download/view the uploaded file now.");
} else {
print("An unknown error has occurred.");
}
} else {
print("");
}
?>
</div>
</div>
<div class="col-xs-2">
<div class="form-group">
<button type="submit" class=
"btn btn-primary">Upload File</button> <a href=
"http://alydus.net/upload/uploads/<?=$new_name; ?>"
class="btn btn-primary" role=
"button">Download/view uploaded file</a>
</div>
</div>
</div>
</form>
</div>
<div class="container" style=
"margin-top: 30px;margin-bottom: 30px">
<div class="row">
<div class="span12">
<div class="well">
<form role="form" enctype="multipart/form-data"
method="post">
<h3>
Instructions
</h3>
<hr />
<div class="row">
<div class="col-xs-6">
<div>
<ul>
<li>Click choose file
</li>
<li>Select your file you'd like to
upload
</li>
<li>Click upload file once
</li>
<li>When the file is finished you
should see a complete message, then
click view/download uploaded file
</li>
<li>You can then copy the link and send
it to anyone so they can view your
images, your html files, and even
download your files!
</li>
</ul>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="container" style=
"margin-top: 30px;margin-bottom: 30px">
<div class="row">
<div class="span12">
<div class="well">
<form role="form" enctype="multipart/form-data"
method="post">
<h3>
Files Uploaded
</h3>
<hr />
<div class="row">
<div class="col-xs-6">
<div style=
'width: 1015px; height: 2500px; overflow: hidden;'>
<center>
<iframe style=
'width: 1015px; height: 2500px;' src=
'http://alydus.net/upload/uploads/index.php'>
</iframe>
</center>
</div>
</div>
<div class="col-xs-2"></div>
<center>
© <?php echo date("Y"); ?> Copyright
Alydus.net
</center>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
您可以在行动,在http://alydus.net/upload
有太多可能的答案,或者对这种格式太好的答案太长。请添加详细信息以缩小答案集或隔离可以在几个段落中回答的问题。我建议您找到一个开发论坛(可能是[reddit](https://www.reddit.com/)?)找出共性。然后,当您遇到特定的编码问题时,请回到StackOverflow,我们很乐意提供帮助。 –
对不起周杰伦,我并不是在寻找'一般'帮助,我只是需要任何方法,我可以做到这一点。我现在更新我的帖子。谢谢。 – Alydus