加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

php 文件上传的简单示例

发布时间:2020-05-25 04:59:52 所属栏目:PHP 来源:互联网
导读:php 文件上传的简单示例

感兴趣的小伙伴,下面一起跟随脚本之家 jb51.cc的小编来看看吧。
经测试代码如下:


<?php
/**
 * 文件上传
 *
 * @param 
 * @arrange (512.笔记) jb51.cc
 **/
//if they DID upload a file...
if($_FILES['photo']['name'])
{
 //if no errors...
 if(!$_FILES['photo']['error'])
 {
  //now is the time to modify the future file name and validate the file
  $new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file
  if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB
  {
   $valid_file = false;
   $message = 'Oops!  Your file's size is to large.';
  }
 
  //if the file has passed the test
  if($valid_file)
  {
   //move it to where we want it to be
   move_uploaded_file($_FILES['photo']['tmp_name'],'uploads/'.$new_file_name);
   $message = 'Congratulations!  Your file was accepted.';
  }
 }
 //if there is an error...
 else
 {
  //set that to be the returned message
  $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['photo']['error'];
 }
}
 
//you get the following information for each file:
$_FILES['field_name']['name']
$_FILES['field_name']['size']
$_FILES['field_name']['type']
$_FILES['field_name']['tmp_name']


/*** 来自:脚本之家 jb51.cc(jb51.cc) ***/ 
?>

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读