Username: Save?
Password:
Home Forum Links Search Login Register*
    News: Keep The TechnoWorldInc.com Community Clean: Read Guidelines Here.
Recent Updates
[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 24, 2024, 11:48:22 AM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[April 03, 2024, 06:11:00 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[March 06, 2024, 02:45:27 PM]

[February 14, 2024, 02:00:39 PM]
Subscriptions
Get Latest Tech Updates For Free!
Resources
   Travelikers
   Funistan
   PrettyGalz
   Techlap
   FreeThemes
   Videsta
   Glamistan
   BachatMela
   GlamGalz
   Techzug
   Vidsage
   Funzug
   WorldHostInc
   Funfani
   FilmyMama
   Uploaded.Tech
   MegaPixelShop
   Netens
   Funotic
   FreeJobsInc
   FilesPark
Participate in the fastest growing Technical Encyclopedia! This website is 100% Free. Please register or login using the login box above if you have already registered. You will need to be logged in to reply, make new topics and to access all the areas. Registration is free! Click Here To Register.
+ Techno World Inc - The Best Technical Encyclopedia Online! » Forum » THE TECHNO CLUB [ TECHNOWORLDINC.COM ] » Programming Zone » PHP
 PHP: Delete or unlink a file on the server
Pages: [1]   Go Down
  Print  
Author Topic: PHP: Delete or unlink a file on the server  (Read 1195 times)
Khushi
Global Moderator
Adv. Member
*****



Karma: 4
Offline Offline

Posts: 329

Hello!!


View Profile
PHP: Delete or unlink a file on the server
« Posted: January 03, 2007, 12:32:20 AM »


PHP has the capacity to work with server-side files in many ways creating, opening, reading, and writing. When you are done with a file, it is a simple matter to delete it using a PHP script.

When a file is no longer needed on the server, as with temporary files, it can be deleted using the unlink() function. To delete a file referenced by the variable $tmpfile, use the following code:

Code:
$tmpfile = "/tmp/somefile.txt"; 
unlink($tmpfile);

The unlink() function returns true if the file was successfully deleted and false if there was a problem.

If there is a problem, it is most likely because you do not have permission to delete the file. In the case of UNIX filesystems, unlinking a file requires write access to the directory containing the file, not to the file itself. If PHP created the file initially, then this is not an issue since the directory must be writable to create a file.

If this doesn't seem reasonable, think about a directory as a file which contains the information about the contents of the directory. To delete a file, no changes are required to the file, but the directory containing the file must be altered to reflect the deletion. Therefore, only the directory must be writable by the user in order to remove the file.

Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Copyright © 2006-2023 TechnoWorldInc.com. All Rights Reserved. Privacy Policy | Disclaimer
Page created in 0.188 seconds with 24 queries.