php删除文件
如何用php删除文件呢?
php中有个函数叫作unlink。只要一个参数,表示文件路径就行了。
bool unlink ( string filename)
成功删除返回真,否则返回假。
这次我在项目中,需要用到删除文件操作。为了完美的操作,首先要判断一下这个路径的文件是否存在,用file_exists函数。如若存在,则去删除文件。具体代码如下:
if(file_exists($aurls[$i])){
unlink($aurls[$i]);
}
其中$aurl[$i]一看就知道是在循环中的一个数组。哈哈,没错,我将所要删除的多个文件的路径存到一个数组中,然后遍历。如果文件存在呢,就删除之。为了更有成就感,我在前后加了两句话,变成了这样:
echo "正在删除".$aurls[$i]."……<br />";
if(file_exists($aurls[$i])){
unlink($aurls[$i]);
}
echo "成功删除".$aurls[$i]."<hr />";
这样结果就好看了,能明确地看到程序执行结果。
相关文档:
windows下开发php扩展网上很多资料都说需要Cygwin,其实完全可以不必安装该东东。没错,是可以在linux下生成骨架后拷到windos下来用,但是,如果没有linux环境呢?什么,装虚拟机?我晕,你咋又绕回去了- -! 除了编译外,shell环境主要就是为了生成扩展的骨架,其实骨架已经在php源码包中了了,我们只需要把相关名字替换一 ......
In the directory where you plan to install Elgg, do the following:
Create the file .htaccess and add these two lines
RewriteEngine on
RewriteRule ^testing.php$ modrewrite.php
This tells the webserver to load modrewrite.php when testing.php is
requested.
In order to get this test to work on ......
<?php
/********************************************************************
* FileName: class.msn.php
* by changwei, 2010-4-13
* Contact MSN: changwei0112@hotmail.com
* 获取MSN好友Email列表
*
========================== ......
刚写完前面的日志,又发现一个Bug:
根据Oracle官方提供的说明:
http://www.oracle.com/technology/documentation/berkeley-db/db/programmer_reference/ext_php.html
class Db4的声明如下:
class Db4 {
function Db4($dbenv = null) {} // create a new Db4 object using
......