Questions tagged [unlink]

Refers to removing a file from a filesystem.

This tag is appropriate for questions about deleting a file from a filesystem whether by using a language-specific function such as Perl or PHP's unlink or by making a system call such as Unix's unlink.

Wikipedia has more information about unlink.

526 questions
11
votes
9 answers

PHP does unlink function works with a path?

I would like to remove a file from a folder in PHP, but I just have the path to this file, would it be ok to give the path to unlink? For example unlink('path/to/file.txt'); If this doesn't work, the only way to get rid of those files would be to…
Masiar
  • 20,450
  • 31
  • 97
  • 140
11
votes
1 answer

PHP can't unlink file after fclose

After my script finishes I can delete the file, but while it's running I can't touch it, even after an fclose(). Here is the code I'm trying to use: $Files = glob("$_SERVER[DOCUMENT_ROOT]/files/*.csv"); $File = fopen($Files[0], "r"); …
Brian Leishman
  • 8,155
  • 11
  • 57
  • 93
11
votes
11 answers

How to unlink (delete) an image in CodeIgniter

I try to unlink an image in CodeIgniter, but the unlink function shows: notice Undefined index: userfile Here is my code input->post('logo_name',TRUE); …
Arul
  • 111
  • 1
  • 2
  • 9
11
votes
8 answers

PHP Unlink Not working

I am trying to delete photo in php using unlink. I have used it earlier on other server but this time it is not working. I have used absolute path for a test but still does not works: I have used it as: unlink('img1.jpg'); and…
Sunil
  • 237
  • 2
  • 4
  • 13
9
votes
4 answers

Overwrite file on server (PHP)

I am making an Android application that need to be able to push files onto a server. For this I'm using POST and fopen/fwrite but this method only appends to the file and using unlink before writing to the file has no effect. (file_put_contents has…
Luke Pring
  • 992
  • 3
  • 11
  • 16
9
votes
5 answers

How to Delete ALL .txt files From a Directory using PHP

Im trying to Delete ALL Text files from a directory using a php script. Here is what I have tried..... I dont get an Error when I run this, yet It doesnt do the job. Is there a snippet for this?…
Ron
  • 379
  • 3
  • 8
  • 20
9
votes
2 answers

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…
CdB
  • 4,738
  • 7
  • 46
  • 69
9
votes
5 answers

How to delete all files except one from a directory using PHP?

I have a few directories with some files in them: /test1/123.jpg /test1/124.jpg /test1/125.jpg /test2/123.jpg /test2/124.jpg I want to delete all except for /test1/124.jpg or /test2/124.jpg? I know the directory name and the file name. Is there a…
Patrioticcow
  • 26,422
  • 75
  • 217
  • 337
7
votes
2 answers

unlink/file_exists and file not found

I have this code in my application, often run in race condition by severals users of my application clearstatcache(TRUE, $filepath); if(file_exists($filepath)) unlink($filepath); But, for this line of code, I still have severals errors each day…
Cédric Girard
  • 3,358
  • 7
  • 37
  • 52
7
votes
2 answers

Git Merge: error: unable to unlink old : No such file or directory

I'm pulling a branch into master in order to merge it. Command I'm running is (while having master checked out): git pull origin feature/some_branch Unfortunately it seems my colleagues have performed some (what I would think benign) file deletions…
Skwiggs
  • 1,348
  • 2
  • 17
  • 42
7
votes
2 answers

Git - Unlink of file .idx and .pack failed (The only process owned handle to this file is git.exe)

Please, look at this picture! could be git that stupid? Git couldn't unlink some file, but only git.exe is holding a handle to this file. (Permissions are ok - Full control) Please, is there a safe solution for this problem? My Git version is…
plaurinc
  • 93
  • 1
  • 7
7
votes
1 answer

Difference between unlink and rm on unix

Whats the real different between these two commands? Why is the system call to delete a file called unlink instead of delete?
veeyikpong
  • 829
  • 8
  • 20
7
votes
4 answers

PHP: unlink cannot delete file even the file exists and writable

I've been trying to figure out why unlink is not working. I've tried stackoverflow previous questions and answers but no luck. The exact filename that needs to be deleted is 'upload/test.png'. First I made a check if file exists. $filename =…
nickanor
  • 637
  • 2
  • 12
  • 18
6
votes
2 answers

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…
Joshua
  • 4,270
  • 10
  • 42
  • 62
6
votes
1 answer

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?
JRL
  • 76,767
  • 18
  • 98
  • 146
1
2
3
35 36