仅仅实现一个小的上传功能,并没有过多注意代码的质量
html
<html>
<head><title>test the php</title></head>
<body>
<h1> upload new file to website</h1>
<form action="test3.php" method="post" enctype="multipart/form-data">
<div>
<input type="hidden" name="MAX_SIZE" value="100000000"/>
<lable for="userfile" >upload a file :</lable>
<input type="file" name="userfile" id="userfile" />
<input type="submit" value="submit" />
</div>
</form>
</body>
</html><?php
if($_FILES['userfile']['error'] > 0)
{
echo "upload error"."</br>";
exit;
}
else
{
echo "upload ok"."</br>";
}
if(file_exists("/var/www/".$_FILES['userfile']['name']))
{
echo "file already exists"."</br>";
exit;
}
else
{
move_uploaded_file($_FILES['userfile']['tmp_name'], "/var/www/".$_FILES['userfile']['name']); //必须修改上传文件名,否则脚本退出会自动删除上传文件
echo "upload finished<br>";
}
?>注意:php.ini文件中有关上传的参数配置
file_uploads, upload_tmp_dir, upload_max_filesize, post_max_size
版权声明:本文为博主原创文章,未经博主允许不得转载。
以上就介绍了php文件上传功能,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号