PHPsu
MANUAL ZH  |  EN
     


Current Position :| index>PHP教程> 一段php上传图片代码

一段php上传图片代码

FROM: AUTHOR: TIME:2008-08-12 HITS:

<?
if($upok){
$open = opendir("images");
if($open==0)
{
mkdir("images");
}
$imagename = $_POST['imagename'];
$file = ($_FILES['upfile']['name']);
$file_name = ($_FILES['upfile']['tmp_name']);

phpsu.com is a free phpscool

$image_type = array('jpg', 'gif', 'bmp', 'jpeg', 'pcx', 'tiff', 'png', 'svg');
if (($pos = strrpos($_FILES['upfile']['name'], '.')) !== false) {
    $file_ext = strtolower(substr($_FILES['upfile']['name'], $pos + 1));
}
if (!in_array($file_ext, $image_type))
{
echo "<script>alert('只能上传图片格式的文件');location.href='index.php';</script>";
    exit();
}
$up = move_uploaded_file($file_name,"images/$file");
if($up==1)
{
echo "<script>alert('上传成功!$upfile_name');location.href='index.php';</script>";
exit();
}
else
{
echo "<script>alert('上传失败!');location.href='index.php';</script>";
exit();
}
}
?> welcome to phpsu.com

<html>
<head>
<title>PHP图片上传</title>
</head>
<body>
<div align=center>
<table cellspacing="0" cellpadding="0" border="0">
<form action="index.php" method="post" name="UL" enctype="multipart/form-data">
<tr><td>图片源文件:</td><td><input type="file" name="upfile" /></td></tr>
<tr><td>图片说明:</td><td><textarea name="imagename" value="图片说明" rows="4" cols="25"></textarea></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="upok" value="上传">&nbsp;&nbsp;<input type="reset" value="重置" /></td></tr>
</form>

http://www.phpsu.com


</table>
</div>
</body>
</html>
welcome to phpsu.com


TITLE:一段php上传图片代码
Previous:for、while、foreach性能
Next:None
Copyright 2008 The PHPsu All rights reserved. This mirror generously provided by: .Hp Inc.
Last updated: Tue Aug 12 23:53:48 GMT-8 2008