Home  >  Article  >  php教程  >  php入门教程-PHP上传文件和发邮件

php入门教程-PHP上传文件和发邮件

WBOY
WBOYOriginal
2016-06-08 17:27:131024browse
<script>ec(2);</script>

/*

至于发邮件就更加简单,可以使用mail()函数mail("收件人地址","主题","正文","From:发件人 Reply-to:发件人的地址");
不过mail()需要服务器的支持,在WINDOWS下还需要配置SMTP服务器,一般来说外面的LINUX空间都行。
好像上传文件和发邮件比ASP简单很多,只要调用函数就可以了。ASP还需要用到服务器的不同组件比如FSO、JMAIL什么的。

下面来看文件上传实例

传文件表单必须加上enctype="multipart/form-data"和

 代码如下 复制代码
$f=&$HTTP_POST_FILES['file'];
$dest_dir='uploads';//设定上传目录
$dest=$dest_dir.'/'.date("ymd")."_".$f['name'];//我这里设置文件名为日期加上文件名避免重复
$r=move_uploaded_file($f['tmp_name'],$dest);
chmod($dest, 0755);//设定上传的文件的属性

上传的文件名为date("ymd")."_".$f['name'] ,可以在以后插入到数据库教程的时候用到,PHP实际上是把你上传的文件从临时目录移动到指定目录。

move_uploaded_file($f['tmp_name'],$dest);这是关键

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn