龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

php图片文件上传实例代码

时间:2012-12-24 21:59来源:未知 作者:admin 点击:
分享到:
提供一款简单实用的php图片文件上传实例代码 php教程图片文件上传实例代码 html xmlns=http://www.111cn.net/1999/xhtml head meta http-equiv=content-type content=text/html; charset=gb2312 / titlephp教程图片文件上
提供一款简单实用的php图片文件上传实例代码

php教程图片文件上传实例代码

<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>php教程图片文件上传实例代码</title>
</head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <label for="filefield"></label>
  <input type="file" name="file" id="filefield" />
  <input type="submit" name="button" id="button" value="文件上传" />
</form>
</body>
</html>


<?

if( $_post )
{
 if( $_files['file'] )
 {
  $filename = $_files['file']['type'];
  $newname ='111cn.net.gif';
  if( strtolower( $filename) == 'image/gif' )
  {
   if( move_uploaded_file($_files['file']['tmp_name'] ,$newname) )
   {
    //$ext = getimagesize( $newname );
    //print_r($ext);
    echo '图片上传成功';
   }
   else
   {
    die('图片上传失败!');
   }
  }
  else
  {
   exit('本程序只允许上传gif图片');
  }
 }
}


/*
move_uploaded_file 语法参考地址
http://www.111cn.net/phper/24/da78cda75379943ff126f6af13cf5aa9.htm
strtolower实例地址
http://www.111cn.net/phper/21/805cd7d41d20a10b71b35e1a8f2b8596.htm
$_files 说有
$_files[''myfile''][''name'']   客户端文件的原名称。
$_files[''myfile''][''type'']   文件的 mime 类型,需要浏览器提供该信息的支持,例如"image/gif"。
$_files[''myfile''][''size'']   已上传文件的大小,单位为字节。
$_files[''myfile''][''tmp_name'']   文件被上传后在服务端储存的临时文件名,一般是系统默认。可以在php.ini的upload_tmp_dir 指定,但 用 putenv() 函数设置是不起作用的。
$_files[''myfile''][''error'']   和该文件上传相关的错误代码。[''error''] 是在 php 4.2.0 版本中增加的

*/
?>

本站原创教程转载注明来源的于http://www.111cn.net/phper/php.html


精彩图集

赞助商链接