unlink

how to delete a single line in a txt file with php

蹲街弑〆低调 提交于 2019-12-20 01:34:47
问题 i was wondering if it is posible to delete a single line in a txt file with php. I am storing emailadresses in a flat txt file named databse-email.txt I use this code for it: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { $email = $_POST['email-subscribe'] . ',' . "\n"; $store = file_put_contents('database-email.txt', $email, FILE_APPEND | LOCK_EX); if($store === false) { die('There was an error writing to this file'); } else { echo "$email successfully added!"; } } ?> Form: <form action="

How to avoid UNLINK security risks in PHP?

此生再无相见时 提交于 2019-12-19 07:44:09
问题 I'm using UNLINK with PHP and AJAX . I know that in this way is very dangerous, because everyone can delete any files. But I need to use AJAX because I can't reload the page when I delete the files. So how should I do to allow to delete the file only for the user who owns it? Please let me know other things too if you think I'm doing here something wrong or something else what you have in mind and you think that it will be useful : ) My PHP code: <?php $photo_id = $_GET['photo_id'];

Guaranteed file deletion upon program termination (C/C++)

最后都变了- 提交于 2019-12-17 23:06:43
问题 Win32's CreateFile has FILE_FLAG_DELETE_ON_CLOSE , but I'm on Linux. I want to open a temporary file which will always be deleted upon program termination. I could understand that in the case of a program crash it may not be practical to guarantee this, but in any other case I'd like it to work. I know about RAII. I know about signals. I know about atexit(3) . I know I can open the file and delete it immediately and the file will remain accessible until the file descriptor is closed (which

Unlink and SplFileObject

て烟熏妆下的殇ゞ 提交于 2019-12-13 13:03:41
问题 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? 回答1: I would not recommend this, because PHP closes the file behind scenes for you. If you take a look at the 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

删除目录的符号链接

蹲街弑〆低调 提交于 2019-12-12 22:01:42
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 我有一个重要目录的符号链接。 我想摆脱那个符号链接,同时保持它背后的目录。 我试过 rm 然后回来 rm: cannot remove 'foo' 。 我尝试了 rmdir 并找回了 rmdir: failed to remove 'foo': Directory not empty 然后我通过 rm -f , rm -rf 和 sudo rm -rf 进展 然后我去寻找我的备份。 有没有办法摆脱符号链接,而不是用洗澡水扔掉婴儿? #1楼 使用 rm symlinkname 但不要在末尾包含正斜杠(不要使用: rm symlinkname/ )。 然后,您会被询问是否要删除符号链接, y 回答yes。 #2楼 如果rm无法删除符号链接,您可能需要查看包含符号链接的目录的权限。 要删除目录条目,您需要对包含目录具有写入权限。 #3楼 使用“unlink”命令并确保 不在 最后使用/ $ unlink mySymLink unlink()从文件系统中删除名称。 如果该名称是文件的最后一个链接,并且没有进程打开该文件,则该文件将被删除,并且其使用的空间可供重用。 如果名称是文件的最后一个链接,但任何进程仍然打开文件,则文件将保持存在,直到引用它的最后一个文件描述符关闭。 我认为如果我正确阅读它可能会有问题。

Recursive delete

ぐ巨炮叔叔 提交于 2019-12-12 07:16:10
问题 I have this code to recursive delete files and directories. It works fine but has a little problem. If $path = /var/www/foo/ it will delete everything inside of foo, but not foo. I want to delete foo directory too. Any idea? 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(!

Laravel 5: Uploaded image can't be displayed and file permission

时间秒杀一切 提交于 2019-12-12 04:24:05
问题 In my Laravel 5 project, I uploaded image to my sub folders of the public folder. Example: public/uploads/logos/imagename.jpg. The image is uploaded successfully but I have two problems: I can't display the image in the view using <img src="uploads/logos/imagename.jpg"> . The error says that file is not found. When using below code to delete the image, I got another problem of file permission: $path ="uploads/logos/imagename.jpg"; if(file_exists($path)) { unlink($path); } Please kindly advise

unlink() function not working with variables? [duplicate]

别来无恙 提交于 2019-12-12 03:59:03
问题 This question already has answers here : Can I echo a variable with single quotes? (10 answers) Closed 6 years ago . Im having some troubles unlinking files from a directory. I'll try to explain it as good as i can. Im trying to delete a file from a directory, first i get the file name from my database, where is stored in field "avatar". these are my involved vars: $avatar1=mysqli_query($con,"Select avatar from users where user='$_SESSION[Username]'"); $avatar2=mysqli_fetch_array($avatar1);

unlink not working with space in foldername path

安稳与你 提交于 2019-12-12 03:13:31
问题 I read a few threats on escaping but doesn't work. it works with a path without spaces fine.... ($subfolder contains spaces) $subfolder = "this a subf"; $filepath = "/var/www/domain/$subfolder/$imagetodelete"; $filepath = str_replace(" ", "\ ", $filepath); unlink($filepath); // correct if $subfolder/path contains no spaces echo $filepath; 回答1: $filepath = str_replace(" ", "\ ", $filepath); The problem here is that you are escaping the space character in PHP, not actually inserting a backslash

Delete (unlink) or Create (fwrite) file with PHP when file is in use

被刻印的时光 ゝ 提交于 2019-12-11 19:39:40
问题 I am running a website with a LAMP system. Contents come from a database. For caching purposes, I create files on my webserver (containing cachable contents) (via fwrite() ). Every once in a while I am deleting the cache files (via unlink() ). File creation and deletion is done with a cronjob. My question is: what happens when a visitor to my website is currently browsing (=requesting from webserver) file A.php and I am trying to write to or delete this very same file A.php. To be precise: