www.webdeveloper.com
Results 1 to 4 of 4

Thread: Stat failed message using stat() functions

  1. #1
    Join Date
    Oct 2008
    Location
    moreno valley, California ,usa
    Posts
    161

    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 streamermission 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

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,623
    What happens if you use $pic_folder in those lines instead of $cur_dir? (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 [php]...[/php] tags, it makes it a lot easier to read.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Nov 2008
    Posts
    2,477
    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)

  4. #4
    Join Date
    Oct 2008
    Location
    moreno valley, California ,usa
    Posts
    161
    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.

    PHP Code:

    //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_folder0777);//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); 
    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
    Last edited by captsig; 08-06-2010 at 01:07 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles