好的,所以我找到了一个上传脚本,并添加了适合我的会话的调整。如果会话未登录,它会回显图像,但如果会话已登录,则显示文件上传器。问题是,有人可以将有害的 PHP 脚本上传到这里,我只希望它用于图像。有什么建议可以只制作我的代码图像吗?我尝试添加过滤器,但这不起作用。这是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload your own picture of Bouncy!</title>
</head>
<style type='text/css'>
body {
background-image:url('../membership/sitebg.png');
background-repeat:repeat-x;
background-color:#ffffff;
}
a {
color: #093D03;
text-shadow:0px 0px 5px #ffffff;
}
a:visited {
color: #093D03;
}
a:active {
color: #093D03;
}
a:hover {
color: #1AFF00;
}
</style>
<?php
session_start();
if ($_SESSION['loggedin'] == true)
{
echo "<br />";
echo "<br />";
echo "<center><font face='arial'>Welcome to the funny picture uploader,<b> ".$_SESSION['username'];
echo "</b><br /><a href='http://x.org/membership/logout.php'>Logout</a> | <a href='#'>More</a> | <a href='http://x.org'>Home</a>";
echo "<br />";
echo "<br />";
$max_no_img=1; // Maximum number of images value to be set here
echo "<form method=post action='' enctype='multipart/form-data'>";
echo "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>";
for($i=1; $i<=$max_no_img; $i++) {
echo "<tr><td>Images $i</td><td>
<input type=file name='images[]' class='bginput'></td></tr>";
}
echo "<tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr>";
echo "</form> </table>";
while(list($key,$value) = each($_FILES['images']['name']))
{
//echo $key;
//echo "<br>";
//echo $value;
//echo "<br>";
if(!empty($value)){ // this will check if any blank field is entered
$filename =rand(100000000000000,10000000000000000000).$value; // filename stores the value
$filename=str_replace(" ","-",$filename);// Add _ inplace of blank space in file name, you can remove this line
$add = "pictures/$filename"; // upload directory path is set
//echo $_FILES['images']['type'][$key]; // uncomment this line if you want to display the file type
//echo "<br>"; // Display a line break
copy($_FILES['images']['tmp_name'][$key], $add);
echo "<center><b>Your picture will be stored at:</b></center> ";
echo "<center><a href='http://bouncygames.org/$add'>Click here to view your image!</a></center>";
// upload the file to the server
chmod("$add",0777); // set permission to the file.
} }
} else {
echo "<br /><center><img src='sorry.png'><br />
<a href='x'><img src='button-to-join.png'></a>
</center>";
}
?>
我的问题: 我怎样才能让这个只上传图片?