SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    help needed with upload script

    found this code on web to make sure only jpg etc uploaded

    PHP Code:
    if ((($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/pjpeg"))
    && (
    $_FILES["file"]["size"] < 20000))
      {
      if (
    $_FILES["file"]["error"] > 0
    dont know how to fit it into my script if any one can help
    this is my script to post

    PHP Code:
    //This gets all the other information from the form
    $state=$_POST['state']; 
    $type=$_POST['type'];
    $area=$_POST['area'];
    $desc=$_POST['desc'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $tel=$_POST['tel'];
    $pnum=$_POST['pnum'];
    $date date("d-m-Y");
    $pname=$pnum.".jpg";
    move_uploaded_file($_FILES['pic']['tmp_name'], 'uploads/'.$pname);
    // Connects to your Database 
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  2. #2
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    have tried to do it myself this is what i have done but only get a blank page

    PHP Code:
    <?php 
     $correctAnswer 
    4;
     if(
    $_POST['leg'] != $correctAnswer) {
     
    // send em away
     
    header("Location: http://www.plymouth.com/error-page.html");
     exit();
     } 
    //This gets all the other information from the form
    $state=$_POST['state']; 
    $type=$_POST['type'];
    $area=$_POST['area'];
    $desc=$_POST['desc'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $tel=$_POST['tel'];
    $pnum=$_POST['pnum'];
    $date date("d-m-Y");
    $pname=$pnum.".jpg";
    {
    if (((
    $_FILES["pic"]["type"] == "image/gif")
    || (
    $_FILES["pic"]["type"] == "image/jpeg")
    || (
    $_FILES["pic"]["type"] == "image/pjpeg"))
    && (
    $_FILES["pic"]["size"] < 20000))
      {
      if (
    $_FILES["pic"]["error"] > 0)
        {
        echo 
    "Return Code: " $_FILES["pic"]["error"] . "<br />";
        }
      
      else
         
    move_uploaded_file($_FILES['pic']['tmp_name'], 'uploads/'.$pname); 
        }
      }
      else
      {
      echo 
    "Invalid file";
      }

    // Connects to your Database
    cheers
    Doug
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  3. #3
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:
    PHP Code:
    <?php
    $correctAnswer 
    4;
    if (isset(
    $_POST['leg']) && $_POST['leg'] != $correctAnswer)
    {
        
    // send em away
        
    header("Location: http://www.plymouth.com/error-page.html");
        exit();
    }

    //This gets all the other information from the form
    $state $_POST['state'];
    $type $_POST['type'];
    $area $_POST['area'];
    $desc $_POST['desc'];
    $name $_POST['name'];
    $email $_POST['email'];
    $tel $_POST['tel'];
    $pnum $_POST['pnum'];
    $date date("d-m-Y");
    $pname $pnum ".jpg";

    if (((
    $_FILES["pic"]["type"] == "image/gif"
    || (
    $_FILES["pic"]["type"] == "image/jpeg"
    || (
    $_FILES["pic"]["type"] == "image/pjpeg")) 
    && (
    $_FILES["pic"]["size"] < 20000))
    {
        if (
    $_FILES["pic"]["error"] > 0)
        {
            echo 
    "Return Code: " $_FILES["pic"]["error"] . "<br />";
        }
        else
            
    move_uploaded_file($_FILES['pic']['tmp_name'], 'uploads/' $pname);
    }
    else
    {
    echo 
    "Invalid file";
    }
    my mobile portal
    ghiris.ro

  4. #4
    SitePoint Addict
    Join Date
    Jun 2007
    Location
    Plymouth uk
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no i am still getting blank page so here is the whole page script

    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title>Lost and Found Registration</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     
    </head>
    <body>
     
     
    <?php 
     $correctAnswer 
    4;
     if (isset(
    $_POST['leg']) && $_POST['leg'] != $correctAnswer

        
    // send em away 
        
    header("Location: http://www.lostpetsplymouth.com/error-page.html"); 
        exit(); 
    }
     
    //This gets all the other information from the form
    $state=$_POST['state']; 
    $type=$_POST['type'];
    $area=$_POST['area'];
    $desc=$_POST['desc'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $tel=$_POST['tel'];
    $pnum=$_POST['pnum'];
    $date date("d-m-Y");
    $pname=$pnum.".jpg";

    if (((
    $_FILES["pic"]["type"] == "image/gif")
    || (
    $_FILES["pic"]["type"] == "image/jpeg")
    || (
    $_FILES["pic"]["type"] == "image/pjpeg"))
    && (
    $_FILES["pic"]["size"] < 20000))
      {
      if (
    $_FILES["pic"]["error"] > 0)
        {
        echo 
    "Return Code: " $_FILES["pic"]["error"] . "<br />";
        }
      
      else
         
    move_uploaded_file($_FILES['pic']['tmp_name'], 'uploads/'.$pname); 
        }
      }
      else
      {
      echo 
    "Invalid file";
      }

    // Connects to your Database 
     
    $dbh=mysql_connect("localhost""vcd""57") or die('I cannot connect to database because: ' .mysql_error()) ; 
    mysql_select_db("pets"); 

    //Writes the information to the database 
    mysql_query("INSERT INTO `register` VALUES ('$id', '$state', '$type', '$area', '$desc', '$name', '$email', '$tel', '$pname', '$date')");

    //compose the mail message        
     
    $msg"New Record\n Region: $region, Name: $name, Email: $email ";       
    //send the mail       
    mail('d@gmail.com','New Record',$msg)

    ?> 

    <?php
    echo "your information has been added to the directory You will be redirected in three seconds!><br /><br /> 

            <div class='info'>If you don't wish to wait, <a href='index.html'>click here</a>"
    ;            
            echo
    '<meta http-equiv="REFRESH" content="2;url=index.html">';
    ?>                    
     
     
    </body>
    </html>
    Last edited by dougvcd; Apr 30, 2009 at 02:49. Reason: more info
    an old man of 60 trying to keep up with the youngsters he he
    http://lostpetsplymouth.net16.net

  5. #5
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    enable error reporting in your script
    and disable header redirect while testing
    PHP Code:
    <?php
    ini_set
    ("display_errors"1);
    error_reporting(E_ALL);

    // print out the FILES array
    print_r($_FILES);
    my mobile portal
    ghiris.ro

  6. #6
    SitePoint Zealot
    Join Date
    Jan 2005
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Check to make sure that the director permissions are set accordingly on the uploads directory.


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
  •