php文件上传系统功能,PHP文件上传

PHP编程语言中的常见的$_FILES系统函数用法有:

$_FILES['myFile']['name'] 显示客户端文件的原名称。

$_FILES['myFile']['type'] 文件的 MIME 类型,例如"image/gif"。

$_FILES['myFile']['size'] 已上传文件的大小,单位为字节。

$_FILES['myFile']['tmp_name'] 储存的临时文件名,一般是系统默认。

$_FILES['myFile']['error'] 该文件上传相关的错误代码。以下为不同代码代表的意思:

0; 文件上传成功。

1; 超过了文件大小php.ini中即系统设定的大小。

2; 超过了文件大小MAX_FILE_SIZE 选项指定的值。

3; 文件只有部分被上传。

4; 没有文件被上传。

5; 上传文件大小为0。

前端

Your Photo:

后端

$valid_file = true;

//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)

{

$new_file_name = $_FILES["photo"]["name"];

echo "Upload: " . $_FILES["photo"]["name"] . "
";

echo "Type: " . $_FILES["photo"]["type"] . "
";

echo "Size: " . ($_FILES["photo"]["size"] / 1024) . " Kb
";

echo "Stored in: " . $_FILES["photo"]["tmp_name"] . "
";

//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'];

}

}

echo $message;

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值