Hi folks 🙂

I'm new to this forum and i've been learning PHP for a month now...

I'm developing a PHP Photoalbum. All the photos reside in a special directory (images). The user of the script can make several subdirectories for different gallery's. In those subdirectories are the photo's.

So I need to make a script that makes a page that let's the user of the album choose a gallery (album.php) and when he clicks on a gallery, a page is produced that shows the photo's in that gallery (gallery.php).

I figured out that the name of the gallery should be passed from album.php to gallery.php by querystring.

Are there built-in PHP functions to read the different directories and post them on the album.php page ?

thx 🙂

    thx yelvington

    another question: how can i check the mime type of an uploaded image??

    thank you 🙂

    thomas

      Thx Cgraz

      So if I wanted to check if the uploaded file is a JPEG before I upload it to the server, I had to enclose the upload code in a IF-statement like this?

      if ($_FILES['userfile']['type'] == "image/jpeg" || $_FILES['userfile']['type'] == "image/gif")
      {
      // upload the file to the server
      }
      
      else
      {
      // print error message
      }
      

      Is this code correct??

        yup, but you could just try to the code and see how it works. try uploading a file that is neither a .jpg or .gif and see if it gets through. That's the best way to learn.

        Cgraz

          Why doesn't this work? 😕

          <?php
          $uploaddir = "C://Documents and Settings//Thomas//Mijn documenten//Webdesign//uploadscript//";
          $uploadfile = $uploaddir. $_FILES['userfile']['name'];
          if ($_FILES['userfile']['type'] == "image/gif") 
          {
          if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
          	{
          	echo ("Het bestand is met succes upgeload naar de server!");
          	unlink($_FILES['userfile']['tmp_name'];
          	}
          
          else
          	{
          	echo ("Het bestand is niet upgeload naar de server! Er heeft zich een fout voorgedaan");
          	unlink($_FILES['userfile']['tmp_name'];
          	}
          }
          }
          ?>
          

          It only works when I delete the first IF-statement to check the MIME-type...

            The reason that it doesn't work is because of some typo’s...
            Look thru the code, you are missing 2 ')' and the last '}' should be removed.

              I corrected the above code like this:

              <?php
              $userfile = "C://Documents and Settings//Thomas//Mijn documenten//Webdesign//uploadscript//" . $_FILES['userfile']['name'];
              if ($_POST['submit']) {
                  if ($_FILES['userfile']['type'] == "image/gif" || $_FILES['userfile']['type'] == "image/jpg") {
                      if (move_uploaded_file($_FILES['userfile']['tmp_name'], $userfile)) {
                          echo ("<b>File succesfully uploaded.</b>");
                          unlink($_FILES['userfile']['tmp_name']);
                      } else {
                          echo ("<b>File was not uploaded.</b>");
                          unlink($_FILES['userfile']['tmp_name']);
                      } 
                  } else {
                      echo ("<b>You can only upload .GIF files.</b>");
                      unlink($_FILES['userfile']['tmp_name']);
                  } 
              } else {
                  echo ("<b>Please use the form to upload images.</b>");
                  unlink($_FILES['userfile']['tmp_name']);
              } 
              
              ?>
              

              I tried to upload a GIF and I also tried to upload a JPEG but no luck 😕

              Could anyone point me out where I made a mistake??

              Thank you 😃

                Write a Reply...