Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 3 of 3

Thread: PHP Help

  1. #1
    Fanatic Enthusiast

    Join Date
    Jan 2010
    Posts
    2,716

    PHP Help

    Ok Heres The Case .,,,Im Attempting To Make A GIF Uploader...
    I Have 2 Files index.php and upload.php

    Index Script
    Code:
    <html>
    <body>
      <form enctype="multipart/form-data" action="upload.php" method="post">
        <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
        Choose a file to upload: <input name="uploaded_file" type="file" />
        <input type="submit" value="Upload" />
      </form>
    </body>
    </html>
    Upload.php Script
    Code:
    <?php
    //?heck that we have a file
    if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
      //Check if the file is gif image and it's size is less than 350Kb
      $filename = basename($_FILES['uploaded_file']['name']);
      $ext = substr($filename, strrpos($filename, '.') + 1);
      if (($ext == "gif") && ($_FILES["uploaded_file"]["type"] == "image/gif") && 
        ($_FILES["uploaded_file"]["size"] < 350000)) {
        //Determine the path to which we want to save this file
          $newname = dirname(__FILE__).'/Uploads/'.$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_file']['tmp_name'],$newname))) {
               echo "It's done! The file has been saved as: ".$newname;
            } else {
               echo "Error: A problem occurred during file upload!";
            }
          } else {
             echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
          }
      } else {
         echo "Error: Only .gif images under 350Kb are accepted for upload";
      }
    } else {
     echo "Error: No file uploaded";
    }
    ?>
    But It Does Not Seem To Work...

  2. #2
    Obsessed Veteran Adam's Avatar



    Join Date
    Nov 2004
    Location
    UK / England
    Posts
    17,271

    Re: PHP Help

    I can't be bothered to compile peoples code each time.

    Just saying
    But It Does Not Seem To Work...
    isn't very helpful. What exactly is the problem, any error messages etc?

    One of arts of programming is learning to debug.

  3. #3
    Fanatic Enthusiast

    Join Date
    Jan 2010
    Posts
    2,716

    Re: PHP Help

    Well It Always Took Me To A Blank Page,.

    Edit:i tried to do a tutorial from w3school but not working for me eaither

    it took me to page where i can see my scripts written,...


 

Posting Permissions

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