/    Sign up×
Community /Pin to ProfileBookmark

Stat failed message using stat() functions

Hello fellow coders,
this is probably a tiresome topic for many of the more competent designers, but I am again confronting a “failed to open stream:permission denied” message when trying to create a directory.

One file creates a directory and allows the upload of pictures into it. No problems here. But another file allows the viewer to change the name of the folder and up load different pictures. In this program, I get the permission denied problem when the routine hits the creation of a new directory.

In trying to attack the problem I am trying to use functions to tell me the various kinds of information on the file; but these functions too are giving me problems.

For example, in the first part of the process where I am not having any problems, I tried to use the following functions to see what the file owner and permissions were at time of creation of the directory:

…because the picture folder name is the product item name, I check to make sure it is unique
… then

if($num>0) {
echo ‘<div class=”error_occur”><h3>The part name you have chosen is already in use; please choose a different name.</h3></div>’;
exit(‘duplicate picture file name has occurred’);
}
else
{
mkdir($pic_folder, 0777);
}
opendir($pic_folder);
$cur_dir=basename($pic_folder);
$user=fileowner($cur_dir);
echo ‘<h3>The file user is:’.’ ‘.$user[‘name’].'</h3>’;
echo ‘<h3>The file permissions are:’.’ ‘.decoct(fileperms($cur_dir)).'</h3>’;

the error message says fileowner(..) failed and fileperms failed and the printed line says file permissions are : 0

Anyone have any suggestions?

captsig

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 05.2010 — What happens if you use [b]$pic_folder[/b] in those lines instead of [b]$cur_dir[/b]? (If you just use the basename() value, then it's going to look for it as a file or directory in the same directory where the script is running.)

PS: If you wrap your code snippets here in the [noparse][code=php]...[/code][/noparse] tags, it makes it a lot easier to read.
Copy linkTweet thisAlerts:
@MindzaiAug 05.2010 — Also fileowner() returns an int not an array (which isn't the cause of your issue but it won't do what you want if NogDog's suggestion works)
Copy linkTweet thisAlerts:
@captsigauthorAug 06.2010 — NogDog and Mindzai,

thank you for your responses; NogDog's suggestion worked on the first file that initially creates the picture folder; however on the second file that allows the viewer to change the folder and pictures within, I'm back to getting the 'stat() failed message along with 'permission denied' at the point I want to create a new picture folder.

I thought I would drop in the relevant code section; I made comments to help clarify what I am trying to do. If anything jumps out at you, please let me know.

[code=php]

//if submitted -process the form input otherwise display the form
if(isset($_POST['submitted']))
{
//remove the current picture folder and picture files
$item=$_POST['item'];

$query3="SELECT item_name, img_lg, img_sm FROM teezers WHERE catnum='$item'";
$result3=mysql_query($query3) or die(mysql_error());
if(!$result3)
{
echo '<h3>There was a problem retrieving picture and folder info from teezers</h3>';
exit;
}
while($row=mysql_fetch_array($result3))
{

//set up the path to the picture folder
$catnum=addslashes($_POST['catnum']);
$pic_folder="../images/".$row['item_name'].'/';
$big_pic=$pic_folder.$row['img_lg'];
$sm_pic=$pic_folder.$row['img_sm'];
$filearray=glob("$pic_folder*");
foreach($filearray as $file)
{
unlink($file);
}
if(is_dir($pic_folder))
{
echo '<h3>This is a folder</h3>';
$fp=rmdir($pic_folder);
}
}//end while

//now create a new folder for the new uploaded pictures

$item_name=addslashes($_POST['item_name']);
$descript=addslashes($_POST['descript']);
$price=(float)$_POST['price'];
$pic_folder="../images/".$item_name.'/';

$user=fileowner($pic_folder);//warning: stat() failed
echo '<h3>The file user is:'.' '.$user['name'].'</h3>';//printed out as a blank
echo '<h3>The file permissions are:'.' '.decoct(fileperms($pic_folder)).'</h3>';//printed a zero and warning stat() failed
chmod('C:/xampp/htdocs/classicwear', 0777);
chmod('C:/xampp/htdocs/classicwear/php/teezers_edit.php', 0777);
chmod('C:xampp/htdocs/classicwear/images/', 0777);
chmod($pic_folder, 0777);//warning: permission denied

//check to see if the item name already exists in the database, if not create a folder by that name
$query="SELECT * FROM teezers WHERE catnum='$catnum'";
$result=mysql_query($query) OR die(mysql_error());

$num=mysql_num_rows($result);
if($num>1) {
echo '<div class="error_occur"><h3>The catalogue number you have chosen is already in use; please choose a different number.</h3></div>';
exit('duplicate catalogue number has occurred');
}
else
{
mkdir($pic_folder,0777);//permission denied
}
opendir($pic_folder);
[/code]


As you can see, I've slapped a '0777' permission setting on everything I can think of that might be relevant.

Thanks in advance.

captsig
×

Success!

Help @captsig spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...