Forum Moderators: coopster

Message Too Old, No Replies

unlink permission denied windows

         

jackvull

10:52 am on May 6, 2008 (gmt 0)

10+ Year Member



I'm getting this error on a Windows server but cannot figure out why.
Other file functions seem to work fine including copy and move
Warning: unlink(C:\KPIUpload\Data.xls) [function.unlink]: Permission denied in C:\Inetpub\wwwroot\Finance\kpiImport.php on line 176


if (file_exists("C:\KPIUpload\Data.xls")) {
unlink("C:\KPIUpload\Data.xls");
}

Is it anyhting to do with the full folder reference?

henry0

5:14 pm on May 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You probably need to figure: Who owns that file?

Navigate to any file or dir by using you fav FTP

on the right pan after the file or dir name is first the list of "right" to perform some tasks,
then comes ownership

bubbasheeko

2:59 am on May 7, 2008 (gmt 0)

10+ Year Member



If I recall the permission belongs to the web server which should unlink the file - that is, if it created it.

jackvull

8:31 am on May 7, 2008 (gmt 0)

10+ Year Member



The server created the file so I can't see why it can't delete it?
Any way to error trap this? It doesn't give a very accurate description.
The permissions on the file and the folder are set to Eveyone Read, write, execute, which is the same as 777 on unix

mrscruff

10:09 am on May 7, 2008 (gmt 0)

10+ Year Member



try:

unlink("C:/KPIUpload/Data.xls");

mrscruff

10:14 am on May 7, 2008 (gmt 0)

10+ Year Member



Sorry, also if you create the file in the same script have you closed the file handler (pos copy or move). Seem to remember having a similar problem, windows won't delete the file as another process has it still open.

jackvull

10:25 am on May 7, 2008 (gmt 0)

10+ Year Member



This is my code further up:

if((!empty($_FILES["uploaded"])) && ($_FILES['uploaded']['error'] == 0)) {
//Check if the file is XLS image and it's size is less than 350Kb
$filename = basename($_FILES['uploaded']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "xls") && ($_FILES["uploaded"]["size"] < 10000000)) {
//Determine the path to which we want to save this file
$newname = dirname(__FILE__).'/upload/'.$filename;
//Check if the file with the same name is already exists on the server
if (!file_exists($newname)) {
//Attempt to move the uploaded file to it's new place
if ((move_uploaded_file($_FILES['uploaded']['tmp_name'],$newname))) {
$msg = "<font color='blue'>It's done! The file has been saved as:<br /> ".$_FILES['uploaded']['name']."</font>";
copy ("$newname","C:/KPIUpload/Data.xls");
} else {
echo "<font color='red'>Error: A problem occurred during file upload!</font>";
}
} else {
$msg = "<font color='red'>Error: File ".$_FILES["uploaded"]["name"]." already exists</font>";
}
} else {
$msg = "<font color='red'>Error: Only .xls files under 10Mb are accepted for upload</font>";
}
} else {
$msg = "<font color='red'>Error: No file uploaded</font>";
}
}