PHP高级编程.doc_第1页
PHP高级编程.doc_第2页
PHP高级编程.doc_第3页
PHP高级编程.doc_第4页
PHP高级编程.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

PHP高级编程上传文件n HTML的设计: 上传文件名称: 要使用form表单,enctype必须为multipart/form-data,否则脚本将不会工作;表单方法是POST需要一个隐藏的表单域,用来标记文件最大字节数一个文件域,用来选择文件n 在PHP脚本中,需要处理的文件保存在$_FILES全局数组中,其中:$_FILESuserfilename - The original name of the file on the client machine. $_FILESuserfiletype - The mime type of the file, if the browser provided this information. An example would be image/gif. This mime type is however not checked on the PHP side and therefore dont take its value for granted. $_FILESuserfilesize - The size, in bytes, of the uploaded file. $_FILESuserfiletmp_name - The temporary filename of the file in which the uploaded file was stored on the server. $_FILESuserfileerror - The error code associated with this file upload. This element was added in PHP 4.2.0 n 上传文件的安全性要保证用户上传的是本地文件,这样可以确保安全性(假如用户修改脚本上传存储在服务器的密码文件也是可以的)is_uploaded_file($_FILESuserfiletmp_name)/若为上传的文件则返回True$upfile = /uploads/.$_FILESuserfilename;move_uploaded_file($_FILESuserfiletmp_name, $upfile)/若为上传的文件则将文件移动到指定的位置使用is_uploaded_file()函数可以检测是否是上传文件,必须要传递上传文件名作为参数。move_uploaded_file也检查是否为上传文件,若是上传文件,则将此文件移动到指定的位置为安全起见,若上传的是Text文件,亦可用strip_tags()函数来移除所有HTML代码(以防止在服务端执行恶意操作)/ reformat the file contents $fp = fopen($upfile, r); $contents = fread ($fp, filesize ($upfile); fclose ($fp); $contents = strip_tags($contents); $fp = fopen($upfile, w); fwrite($fp, $contents); fclose($fp);n 上传文件注意事项若是Windows系统,则要在路径中用 或者 / 来代替 。上传的文件若与已经存在的文件名相同,则会覆盖原文件。需要检查文件名中是是否包含非法字符。上传超大文件需要重新配置Apache服务器,同时还需要调节memory_limit指令等。使用目录函数$current_dir = E:/PHP/; $dir = opendir($current_dir); echo Upload directory is $current_dir; echo Directory Listing:; while ($file = readdir($dir) echo $file; echo ; closedir($dir);opendir() - 打开目录readdir() - 读取目录读取目录后并未按特定顺序排列。若要文件排序则要先读取到数组中,再对数组进行排列。closedir() - 关闭目录rewinddir() - 将所读文件恢复到开始的目录除此之外还可以用DIR类注:在Windows下可以先用$current_dir = /;$dir = opendir($current_dir);来找到当前的根目录获得当前目录的信息dirname() - 返回目录部分basename() - 返回路径disk_free_space() - 返回目录(磁盘)的剩余空间例:E:/PHPnow/htdocs/Source/PHP使用 / 来代替 dirname() is E:/PHPnow/htdocs basename() is Source disk_free_space() is 7044292608 /返回的是E盘的剩余字节数,约6.5G左右创建和删除目录(确保有这个权限)mkdir() - 创建目录(说见PHP手册)rmdir() - 删除目录,必须为空目录获取文件信息(某些函数Windows下不可用)fileatime() - 返回该文件最近被访问的时间filemtime() - 返回该文件最近被修改的时间echo date(Y-m-d H:i:s, fileatime($file)+8*60*60);/要返回北京时间需要再加上8小时;返回值如:2009-07-29 21:20:55*flieowner() - 返回该文件用户标识UID*filegroup() - 返回该文件组标识GID再使用*posix_getpwuid() * posix_getgrgid()转化为容易理解的名字注:*标识的函数不能在Windows下工作fileperms() - 返回文件权限码(Win下可用,一般为40777即可读可写)decoct() - 用于将权限码格式化为8进制数(UNIX下常用)echo File permissions: .decoct(fileperms($file);/这两个函数通常联用filesize()返回文件大小(Win下为0,不知道为什么)其他一些判断函数:is_dir Tells whether the filename is a directoryis_executable Tells whether the filename is executableis_file Tells whether the filename is a regular fileis_link Tells whether the filename is a symbolic linkis_readable Tells whether the filename is readableis_uploaded_file Tells whether the file was uploaded via HTTP POSTis_writable Tells whether the filename is writableis_writeable Alias of is_writable所有文件的状态函数运行很费时间,因此它们的结果都将缓存起来。如果要在变化之前或者变化之后检查文件信息,既要调用下面的函数来清除缓存结果:clearstatcache Clears file status cache如果希望在改变文件数据之前或者之后使用以前的脚本,应该先调用此函数来更新产生的数据。更改文件属性chgrp Changes file groupchmod Changes file modechown Changes file owner创建、删除和移动文件UNIX下:touch() - 创建一个文件unlink() - 删除一个文件Windows下:system(del filename.ext);复制和更名copy Copies filerename Renames a file or directory使用程序执行函数exec - 没有直接的输出;返回命令结果的最后一行passthru - 直接输出到浏览器,参数格式与exec相同system - 此函数将命令的输出回显到浏览器反引号(ESC键下面的那个) - 反引号中的命令可以直接被执行popen Opens process file pointerpclose Closes process file pointerproc_close Close a process opened by proc_open and return the exit code of that processproc_open Execute a command and open

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论