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 ......
环境软件版本介绍:
APACHE 2.0.59
PHP5.2.3
MYSQL5.0.45
GD-2.0.35
Zend Optimizer v3.3.0
  ......
闲话少说,先将它们打包成一个文件就叫fun.php吧
< ?php
function passport_encrypt($txt, $key) {
srand((double)microtime() * 1000000);
$encrypt_key = md5(rand(0, 32000));
$ctr = 0;
$tmp = ''; ......