天道酬勤,学无止境

unlink

Delete file onclick with PHP [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago. I want to delete a file when a user clicks on a delete link. But when I go to my page, the file gets deleted and I don't know why: echo '<h3><a onclick="'.unlink(__FILE__).'">Delete Now!</a></h3>'; What am I doing wrong?

2022-01-17 02:19:11    分类:问答    php   unlink

Using a wildcard in php unlink

I am currently making a php script to graph a bunch of data from a DB, arrange it into text files and then run a GNUPlot script to generate graphs. I have all of this working , now all I need to do is delete the text files I don't need anymore. What I have been trying was gotten from another thread on a different forum: foreach( glob('US_A.2.6.*') as $file ) { unlink($file); } The problem, however, is that it doesn't work. The files have complex end names: US_A.2.6.1.1a.txt US_A.2.6.1.2a.txt US_A.2.6.1.3a.txt US_A.2.6.1.4a.txt US_A.2.6.1.5a.txt US_A.2.6.1.6a.txt And more.

2022-01-17 00:44:50    分类:问答    php   wildcard   unlink

取消链接和 SplFileObject(Unlink and SplFileObject)

问题 是否可以从 SplFileObject 取消链接文件? 我没有看到关闭底层资源的方法,并且文件句柄是私有的,因此无法在考虑到该目标的情况下扩展 SplFileObject。 有什么解决方法吗? 回答1 我不建议这样做,因为 PHP 会在幕后为您关闭文件。 如果你看一下 php src, ext/spl/spl_directory.c : retval.handle = zend_objects_store_put(intern, (zend_objects_store_dtor_t) zend_objects_destroy_object, (zend_objects_free_object_storage_t) spl_filesystem_object_free_storage, NULL TSRMLS_CC); 设置处理程序是为了在所有引用都已用尽时处理对象的清理。 现在,我们检查清理处理程序: spl_filesystem_object_free_storage : case SPL_FS_FILE: if (intern->u.file.stream) { if (intern->u.file.zcontext) { /* zend_list_delref(Z_RESVAL_P(intern->zcontext));*/ } if (!intern->u.file

2022-01-16 10:12:32    分类:技术分享    php   file   unlink   splfileobject

Unlink and SplFileObject

Is it possible to unlink a file from an SplFileObject? I don't see a method to close the underlying resource, and the file handle is private so one can't extend SplFileObject with that goal in mind. Are there any workarounds?

2022-01-15 20:43:07    分类:问答    php   file   unlink   splfileobject

使用通配符删除文件 - exec vs unlink(Delete files using wildcard - exec vs unlink)

问题 我正在处理一个 php 脚本,我想使用通配符 (*) 从给定文件夹中删除一些文件。 我发现了一些像这样的工作示例,其中使用了unlink()和glob()函数。 现在,我想知道,是否也可以使用exec函数和rm -f /path/to/folder/_prefix_*类的命令删除文件? 使用它是否有任何安全风险? 如果可以的话,在性能方面会更好吗? 编辑: 所以,从第一个答案我可以看出,确实,使用exec可能是一个可以接受的解决方案。 性能问题呢? exec选项是否有可能比glob/unlink技术更好(更快/要求更低)? 先感谢您 回答1 因为没有机会注入用户提供的数据,所以在glob/unlink上使用exec没有安全问题。 但是,使用glob/unlink可以定义异常: foreach(glob("delete/*") as $f) { if( $f == "delete/notme.txt") continue; unlink($f); } 并且exec通常在共享服务器上被禁用,因此glob/unlink更便携。 如果您有专门的设置并且不打算放弃它,则无需担心。 回答2 两种选择都可以。 但是,如果您不控制自己的服务器或在共享主机上,则 exec 命令将不可用。 为了节省开支,请使用 glob 并取消链接。

2022-01-15 13:17:47    分类:技术分享    php   exec   unlink

Delete files using wildcard - exec vs unlink

I'm working on a php script, where I want to delete some files from a given folder using wildcard (*). I've found some working examples like this one, where unlink() and glob() function are used. Now, i was wondering, would it also be ok to delete the files using the exec function and a command like rm -f /path/to/folder/_prefix_* ? Are there any security risks taken using this? And if it is ok, would it be better in terms of performance? EDIT: So, from the first answers i can see that indeed, using exec could be an acceptable solution. What about performance issues? Is there any chance the

2022-01-15 10:09:09    分类:问答    php   exec   unlink

无法在php中取消链接文件(unable to unlink file in php)

问题 在一个网站上,我试图实现一个实用程序,该实用程序使用带有复选框选择的 HTML 表单和一个应该实际删除所选图像的 php 文件从某个文件夹中删除所选图像。 表单有效,复选框的值被解析为$_POST['images'] ,其余的 php 代码: $dir=__ROOT__."/images/".$_POST['page']; echo "dir=".$dir."<br>"; $files=array(); $fdir=opendir($dir); while ($i = readdir($fdir)) { //detect images and put them into files() if (strpos(strtolower($i),".jpg")==true&&strpos(strtolower($i),".thumb")==false) $files[]=$i; } closedir($fdir); for($a=0;$a<sizeof($files);$a++) { if(in_array($files[$a],$_POST['images'])) { $file="../images/".$_POST['page']."/".$files[$a]; echo $file."<br>"; echo('<img src="'.$file.'.thumb"><br>')

2021-12-21 01:53:15    分类:技术分享    php   unlink

unable to unlink file in php

On a website I'm trying to implement a utility that removes selected images from a certain folder using an HTML form with checkbox selection and a php-file that should actually remove the selected images. The form works and the values of the checkbox are parsed into $_POST['images'], the php-code to do the rest: $dir=__ROOT__."/images/".$_POST['page']; echo "dir=".$dir."<br>"; $files=array(); $fdir=opendir($dir); while ($i = readdir($fdir)) { //detect images and put them into files() if (strpos(strtolower($i),".jpg")==true&&strpos(strtolower($i),".thumb")==false) $files[]=$i; } closedir($fdir)

2021-12-13 20:52:43    分类:问答    php   unlink

unlink 无法删除文件(unlink cannot delete file)

问题 我对使用 PHP unlink() 在 ubuntu 中删除文件感到沮丧。 我创建了一个非常简单的模拟如下: 使用 766 权限在 /var/www 下创建一个名为“files”的文件夹。 上传文件,在该文件夹中说“image.png”并将权限设置为666 创建一个名为delete.php的php文件,设置权限为644,上传到/var/www目录在浏览器中调用文件(我使用本地主机) “image.png”仍然存在于“files”目录中 这是 delete.php 的 php 脚本: $filename = 'image.png'; $file = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR . $filename; unlink($file); 我还尝试了以下脚本: $filename = 'image.png'; $dir = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'files'; chdir($dir); unlink($filename); 但是还是不能删除文件。 回答1 Unlink 会在失败时发出警告。 检查 E_WARNING 是否对您可见,以了解发生了什么。 它通常归结为用户权限。

2021-12-09 16:43:57    分类:技术分享    php   unlink

递归删除(Recursive delete)

问题 我有这个代码来递归删除文件和目录。 它工作正常,但有一个小问题。 如果 $path = /var/www/foo/ 它将删除 foo 中的所有内容,但不会删除 foo。 我也想删除 foo 目录。 任何的想法? public function delete($path) { if(!file_exists($path)) { throw new RecursiveDirectoryException('Directory doesn\'t exist.'); } $directoryIterator = new DirectoryIterator($path); foreach($directoryIterator as $fileInfo) { $filePath = $fileInfo->getPathname(); if(!$fileInfo->isDot()) { if($fileInfo->isFile()) { unlink($filePath); } else if($fileInfo->isDir()) { if($this->emptyDirectory($filePath)) { rmdir($filePath); } else { $this->delete($filePath); rmdir($filePath); } } } } } 回答1

2021-12-01 22:35:42    分类:技术分享    php   recursion   delete-file   unlink   rmdir