Nov 22, 2009

Deleting Files With PHP - is this possible?

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Deleting Files With PHP - is this possible?

Kushika
It is posible for PHP to delete files on a server? If so, how is this possible? Just out of interest...

Comment/Reply (w/o sign-up)

mastercomputers
To delete files, you use the unlink() function.

Problems you may encounter is the owner of the file is not the script that is calling the unlink, usually if you create the file with the script and then remove it with the script, it would be ok to do so. Another problem is trying to delete a file that's in use, if that's the case, you should always make sure that you've fclose() the file before trying to remove it.


Cheers,


MC

Comment/Reply (w/o sign-up)

Kushika
Thanks for your help!

but let's say if I were to give global permissions via CHMODing the file (like 777), would I still be able to delete it even if the script did not create it?


Comment/Reply (w/o sign-up)

mastercomputers
If that was the case, then it's quite possible, but only a super user or the owner of the file could make those alterations to it.


Cheers,


MC

Comment/Reply (w/o sign-up)

Kushika
But is a file I'm talking about is a PNG image, how can this file have a user 'assigned' to it?

Comment/Reply (w/o sign-up)

mastercomputers
QUOTE(Kushika @ Mar 13 2006, 01:09 AM) *

But is a file I'm talking about is a PNG image, how can this file have a user 'assigned' to it?


All files are owned by someone and belong to a group, usually when you upload a file via FTP, that user who's logged in, will be the owner of that file. Also on your filesystem, you would have the owner of that file, usually an image has permissions 644, which is Owner:read/write Group:read All Others:read. So only the Owner is allowed to make alterations, all the rest can still view the file with no problems.

If you created the image from your graphics program, then you're the owner of it (the person you logged in as). Only super users or yourself may alter the file, all others will only be able to read it. It also depends on where you store the photo, if it's in your home directory and you've made your home directory only viewable by the owner (you) then no one but you or super user could get to it, all the rest would be stopped trying to get into your home directory.

You've obviously heard of chmod, other commands are chgrp (change group) and chown (change owner) which all these commands relate to one another in some way.


Cheers,


MC

 

 

 


Comment/Reply (w/o sign-up)

CrazyPensil
QUOTE(mastercomputers @ Mar 12 2006, 03:42 PM) *

... all others will only be able to read it ...


You've missed that Supervisors or the ones, whose authorites are higher then the one's who'd created or chmod of that file alows him to work write it, he may also whatever he wants with yhat file, despite gid are different.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : deleting, files, php

  1. Magic Quotes And $_files
    (3)
  2. How To Protect Included Files
    (10)
    Hey! How can i make my included files 100% safe. Like if I include a file witht his code.. CODE
    include "bla.php"; How can i make it 100% safe? I know I must close the php tags in the
    included files. but what more =?....
  3. Reading Files And Folders
    (1)
    I am in the process of writing a small content management system for my niche sites and need to be
    able to accomplish the following two items. Any assistance would be appreciated: I have a
    directory that has nothing but sub directories in it and I need to be able to identify each
    directory name and return them in an option drop down selection menu which will be included in an
    identifying URL. ALSO: I am in need of a script that could be included on a returned page
    that will read the content of a table and identify various keywords within the content and pl....
  4. Php File Upload
    About uploading files through php (3)
    Right i have done a check for a tutorial on this as well as a question about it but php is not
    allowed in the search box. So i thought i'd just ask what i want to know. I have a form which
    uploads a file, it refreshes the page, uploads the file and then alerts the user to if the file has
    uploaded. To be honest im not sure why i keep getting the error. But here is the code: This is the
    form that is used for the user to select the file &fid= " method="POST"> Choose a file to
    upload: This is the upload code if ($op == "up"....
  5. Help To Transfer Files Within Hosting Space Using Php
    (4)
    I want to transfer files from one folder to another or an entire folder in my web space. I don't
    want to download it and upload it, can I do this using a PHP script. Please help me. I'm just
    learning the basics of PHP....
  6. How To Edit Php Files?
    (16)
    Hi, You can use frontpage to preview HTML files, but how can I edit and preview PHP files offline.
    I'm not well-known with PHP and I see more and more using this script to manage their site.....
  7. How To Delete Files When Session Ends
    (4)
    Dear Friends I need solution to a problem. The problem is as under: I am creating certain files
    (playlist) in server disk when user selects some songs. The files are created in ram format. What I
    want to do is to delete these files created during a particular session. Is it possible to do so?
    Now I am deleting these files using on Unload event fired by JavaScript. I am using PHP. ....
  8. Php : Variables Included Dont Work In Functions
    Variables from Included files dont work (4)
    Today, I came up with this strange PHP behaviour. Just wanted to know if anyone has any
    suggestions! I make a common variable/function file called config.php. I put in my generally used
    functions in it. Suppose this is my file CODE // -----VARIABLES --- // $a=10,$b.... //
    -----FUCTIONS--- // function doit() { print "A value is " . $a; } ?> Here, suppose we execute
    this file directly. Since A has a global scope, it does work perfectly. But if this same file is
    imported in another file say, mainfile.php CODE // -----VARIABLES --- // $c,$d.... include &#....
  9. How Do I Create And Write To Files?
    creating, writing, deleting files (4)
    Hi, Can someone please tell me how to create files and write to them in PHP. I just want to create
    a simple file containing text, and then be able to read it or update it. Thanks Alfie....
  10. Getting Files From Other Sites
    Using wget (3)
    Hello. A while ago, a friend showed me this PHP code (wget) which allows you to get files from other
    sites. I was a simple one liner type thing. Since my old host (Nytka) went down, I've lost it,
    as has my friend. Do you know anything about wget, and could tell me it?....

    1. Looking for deleting, files, php

See Also,

*SIMILAR VIDEOS*
Searching Video's for deleting, files, php
advertisement



Deleting Files With PHP - is this possible?

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com