SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast judgetules's Avatar
    Join Date
    Dec 2004
    Location
    Newcastle, UK
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Error Creating Directory...

    Warning: mkdir(/gallery/15th_December_2004): No such file or directory in /home/username/public_html/addgallery.php on line 25

    Warning: mkdir(/gallery/15th_December_2004/thumbs/): No such file or directory in /home/username/public_html/addgallery.php on line 25
    This is the error I get when trying to create a directory on my server.

    Why isn't it letting me create the directory? When I tried it on my home server it worked fine.

    Here is the PHP code for adding the gallery.

    Addgallery.php
    PHP Code:
    <?php if (isset($_POST['cid'])){ 
        
    include_once 
    'includes/header.inc.php'?>

    <div id="main">

    <?php // a gallery has been added 

    //add gallery

    $cid $_POST['cid'];
    $gallerydate $_POST['gallerydate'];
    $gallerydate ereg_replace(" ","_",$gallerydate);

    if (
    $cid == '') {
        exit(
    '<p>Please Choose a club.</p>');
        }

    $sql "INSERT INTO gallery SET 
            gallerydate = '
    $gallerydate',
            clubid='
    $cid'";

     
    if (@
    mysql_query($sql)) {
            echo 
    '<h3>Gallery Added.</h3>'mkdir ('/gallery/' $gallerydate0700); mkdir ('/gallery/' $gallerydate '/thumbs/'0700); chdir('./');
          } else {
            echo 
    '<p>Error adding new gallery: ' .
            
    mysql_error() . '</p>';
        }
    ?>

    <p>Gallery Added</p>
    <p><a href="gallery.php">See All Galleries</a></p>
    <p><a href="addgallery.php">Add Another Gallery</a></p>
    <p><a href="index.php">Return Home</a></p>

    </div>

    <?php include_once 'includes/footer.inc.php'; } else { 
        
        require 
    'includes/secure.inc.php'
        include_once 
    'includes/header.inc.php';
        
    //show add gallery form ?>

    <div id="main">

    <h3>Add Gallery</h3>

    <table>
        <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
            <tr><th>Club</th><td>
            
            <select name="cid" size="1">
            <option selected value="">Choose a Club</option>
            <?php $ok = @mysql_query("SELECT id, name FROM club ORDER BY name");
                if (!
    $ok)
                {
                exit (
    '<p>Error performing query: ' mysql_error() . '</p>');
                }
                while (
    $row2 mysql_fetch_array($ok))
                {
                
    $id $row2['id'];
                
    $name $row2['name'];

                echo 
    "<option value=\"$id\">$name</option>"; }?>

            </select></td></tr>

            <tr>

            <th>Date:</th><td><input type="text" name="gallerydate" size="30" /></td></tr>
            
            <tr><td></td><td>
            <input type="submit" value="Add Gallery" class="submit" /></td></tr>
            </form>
    </table>

    </div>

    <?php include_once 'includes/footer.inc.php'; } ;?>
    The error claims to be in this line

    echo '<h3>Gallery Added.</h3>'; mkdir ('/gallery/' . $gallerydate, 0700); mkdir ('/gallery/' . $gallerydate . '/thumbs/', 0700); chdir('./');
    Any help would be much appreciated.
    Still learning the ways of PHP/MySQL.

  2. #2

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You are trying to create the directory below a directory called "gallery" in the root directory. I guess "gallery" is a sub-directory of the current one, so the following should be working.
    PHP Code:
    if (@mysql_query($sql))

        echo 
    '<h3>Gallery Added.</h3>';
        
    mkdir('gallery/' $gallerydate0700);
        
    mkdir('gallery/' $gallerydate '/thumbs/'0700);
        
    chdir('./'); // why that?
    } else echo '<p>Error adding new gallery: ' mysql_error() . '</p>'

  3. #3
    SitePoint Enthusiast judgetules's Avatar
    Join Date
    Dec 2004
    Location
    Newcastle, UK
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I read somewhere that you need to add chdir('./'); after mkdir to enable the dir to be read.

    BTW - I've already tried it with gallery/ as opposed to /gallery/ and it still didn't work!
    Still learning the ways of PHP/MySQL.

  4. #4
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if this will help, but you can try prefixing the directory name with the DOCUMENT_ROOT key from the $_SERVER variable

    e.g.

    PHP Code:
      
      $new_dir 
    $_SERVER['DOCUMENT_ROOT'] . '/gallery/' $gallerydate;
      echo 
    'Creating directory ' $new_dir '<br />';
      if (
    true === mkdir ($new_dir0700))
      {
        echo 
    'Successfully created ' $new_dir '<br />';
      }
      else
      {
        echo 
    'Failed to create' $new_dir '<br />';
      } 

  5. #5
    SitePoint Enthusiast judgetules's Avatar
    Join Date
    Dec 2004
    Location
    Newcastle, UK
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope - that didn't work either, I wonder if it has anything to do with access rights on the server?
    Still learning the ways of PHP/MySQL.

  6. #6

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the gallery directory exist at all?

  7. #7
    SitePoint Enthusiast judgetules's Avatar
    Join Date
    Dec 2004
    Location
    Newcastle, UK
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, well, it seems it i was correct about the directory rights.

    /gallery/ only allowed the owner to read/write/execute whereas I was executing the command from outside the owner area so it wouldn't let me.

    It is fixed now, however, i have another problem.

    PHP Code:
    <?php 

    if (isset($_GET['gallery'])) { //show specified gallery

    $gallery $_GET['gallery']; 
    $gallery ereg_replace("_"," ",$gallery);

    $page_title '- Gallery for ' $gallery;

    include_once 
    'includes/header.inc.php'

    function 
    isPicture($file
        {
        
    $file strtoupper($file);
        
    $pos = (strpos($file,".JPG")||strpos($file,".GIF")||strpos($file,".PNG"));
        if(
    $pos>0) return true ;
         else return 
    false;
        }

    ?>

    <div id="main">

    <h3>Gallery for <?=$gallery?> (<a href="galleries.php">Back to Galleries</a>)</h3>

    <?php //Request the gallery

    $gallery ereg_replace(" ","_",$gallery);

    $galleryDir dir('/gallery/' $gallery); 

        if (isset(
    $_GET['photo'])){ //show specified photo

            
    $photo=$_GET['photo'];

            echo 
    "<img src=\"/gallery/$gallery/$photo\" alt=\"\" /><br />";

            while (
    $afile $galleryDir->read()) 
            {
                if(
    isPicture($afile)) 
                {
                echo 
    "<a href=\"viewgallery.php?gallery=$gallery&photo=$afile\"><img src=\"/gallery/$gallery/thumbs/$afile\" alt=\"\" class=\"gallery\" /></a>";
                }
            } 
        
        } else { 
    //Request all galleries.

            
    while ($afile $galleryDir->read()) 
            {
                if(
    isPicture($afile)) 
                {
                echo 
    "<a href=\"viewgallery.php?gallery=$gallery&photo=$afile\"><img src=\"/gallery/$gallery/thumbs/$afile\" alt=\"\" class=\"gallery\" /></a>";
                }
            }
        }
    } else { 
    Header("Location: galleries.php"); } ?>

    </div>

    <?php include_once 'includes/footer.inc.php';?>
    This is my code for viewing the gallery.

    This is the error I am getting.

    Warning: dir(/gallery/15th_December_2004): failed to open dir: No such file or directory in /home/ptulip/public_html/viewgallery.php on line 30

    Fatal error: Call to a member function on a non-object in /home/ptulip/public_html/viewgallery.php on line 48
    These are the corresponding lines.

    Line 30
    $galleryDir = dir('/gallery/' . $gallery);
    while ($afile = $galleryDir->read())
    Any ideas?
    Still learning the ways of PHP/MySQL.


Bookmarks

Posting Permissions

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