View previous topic :: View next topic |
Author |
Message |
BrandonK -
Joined: 14 Apr 2005 Posts: 10
|
Posted: Tue Jul 11, 2006 6:42 pm Post subject: Delete files outside of Web Directory on Local Machine |
|
|
Is it possible? I searched and saw a couple ppl say that they are doing it, but no one really said how. One idea was to give Abyss a windows user name and then give that user name the proper permissions. How do I give it a specific user name?
I also tried moving the file inside of the web directories, and I can't do it then either.
My php is: Code: |
if (!unlink($ratrackingFile)) {
?>
<div class="error">
<strong>Error Deleting File:</strong><br />
There was an error deleting the file "<?php echo($filesArray[$j]); ?>". It may have already been removed or is currently being used by another program.
</div>
<?php
} |
and it returns the following error:
Quote: | Warning: unlink(c:\_exports\ratracking\44404.text) [function.unlink]: Permission denied ... |
That folder is currently shared w/ write access on my Windows network, and I have tried giving every user I can think of full access to it.
We are using Abyss Web Server X1 (v 2.0.6) on a Windows XP Home Machine. |
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Wed Jul 12, 2006 2:05 am Post subject: |
|
|
If you're sharing the file over your Windows network (i.e. file sharing) with read and write privileges, then anyone on your network can delete your files.
If you're speaking of deleting files using a web browser, it's a little different story. The Abyss Web Server CANNOT do this. It will never delete a file on your hard drive. BUT with a script (Perl, PHP...), any user can potentially delete files anywhere on your hard drive -- if and only if the script is set up to do this.
--------------
More specifically, it looks like you're TRYING to delete a file. Via a script, this is possible. But if that file is locked by another program, it probably cannot be deleted. You can find out if this file is being used by another program by trying to delete it in Windows Explorer. (Then restore it from the Recycle Bin.)
If the file was able to be deleted, please provide the entire script for more in-depth help.
You might also find help at http://www.tizag.com/phpT/filedelete.php. _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Wed Jul 12, 2006 9:11 am Post subject: |
|
|
Does PHP have writing access to the file? Is the file in use by another process? |
|
Back to top |
|
|
BrandonK -
Joined: 14 Apr 2005 Posts: 10
|
Posted: Wed Jul 12, 2006 5:29 pm Post subject: |
|
|
That's the same tutorial I looked at earlier. I'm bascially doing that same thing.
Here's some code:
Code: | <?php
$dir = "/Program Files/Abyss Web Server/htdocs/_exports/ratracking"; //C:\Program Files\Abyss Web Server\htdocs\_exports\ratracking
$filesArray = scandir($dir);
//...
$ratrackingFile = $dir."/".$filesArray[$j];
if (!is_readable($ratrackingFile)) {
echo("<div class=\"error\">Error connecting to the file (\"".$filesArray[$j]."\").</div>");
exit();
}
$handle = @fopen($ratrackingFile,"r");
//...
if (!unlink($ratrackingFile)) {
?>
<div class="error">
<strong>Error Deleting File:</strong><br />
There was an error deleting the file "<?php echo($filesArray[$j]); ?>". It may have already been removed or is currently being used by another program.
</div>
<?php
}
?> |
I have changed the file to now be in my htdocs folder, but I still can't delete it. I've tried changing permissions on the folder, etc., but it hasn't been of any help. I do have full read and write access.
Any ideas?
And the files are .txt files and are not being used by any other program.
EDIT: And I am able to create files in that folder, but I still can't delete them once I'm done. |
|
Back to top |
|
|
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Wed Jul 12, 2006 6:07 pm Post subject: |
|
|
Uh, I don't know if this is the problem, but try:
Code: | $dir = "C:¯\\Program Files\\Abyss Web Server\\htdocs\\_exports\\ratracking"; |
Unless my memory is going I don't think PHP will let you start a path with / on windows.
And you need to use two slashes because one backslash is used for escaping. (And thus with two, the first escapes the second backslash, to make it show.) _________________
|
|
Back to top |
|
|
BrandonK -
Joined: 14 Apr 2005 Posts: 10
|
Posted: Wed Jul 12, 2006 7:20 pm Post subject: |
|
|
$dir works. I can read the file in that way, etc. And when I try to delete the file, the path it shows me is correct, and it doesn't say file not found like if I do this:
Quote: | Warning: unlink(/Program Files/Abyss Web Server/htdocs/_exports/ratracking/44457.textttt) [function.unlink]: No such file or directory |
|
|
Back to top |
|
|
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Wed Jul 12, 2006 8:50 pm Post subject: |
|
|
Can you please post the result of:
Code: | unlink("C:¯\\Program Files\\Abyss Web Server\\htdocs\\_exports\\ratracking\\myfile.txt"); |
Be sure to Change myfile.txt to a real file that it has permission to delete. _________________
|
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
Posted: Wed Jul 12, 2006 9:54 pm Post subject: |
|
|
Simple solution, BrandonK.
The program currently using the file is PHP. Yes, PHP is using the file and therefore will not delete it. The script opens a filehandle to the file, but never closes it.
Quote: | Before you can delete (unlink) a file, you must first be sure that it is not open in your program. Use the fclose function to close down an open file. | Source: http://www.tizag.com/phpT/filedelete.php
Solution:
You must use the above code before you try to unlink the file. Then it will work. _________________ Stephen
Need a LitlURL?
http://CodeBin.yi.org |
|
Back to top |
|
|
BrandonK -
Joined: 14 Apr 2005 Posts: 10
|
Posted: Wed Jul 12, 2006 10:35 pm Post subject: |
|
|
I am idiot.... thanks! :oops: |
|
Back to top |
|
|
MonkeyNation -
Joined: 05 Feb 2005 Posts: 921 Location: Cardiff
|
Posted: Wed Jul 12, 2006 10:40 pm Post subject: |
|
|
Oh sorry, I thought the ...s meant there was code taken out.
I could've told you that, sorry. _________________
|
|
Back to top |
|
|
|