这篇文章主要为大家详细介绍了php 文件上传的简单示例,具有一定的参考价值,可以用来参考一下。
感兴趣的小伙伴,下面一起跟随四海网的小编罗X来看看吧。
<?php
/**
* 文件上传
*
* @param
* @arrange (512.笔记) www.q1010.com
**/
//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']
/*** 来自:四海网(www.q1010.com) ***/
?>
本文来自:http://www.q1010.com/173/551-0.html
注:关于php 文件上传的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:文件上传
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。