Help with upload ..

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joker7

    Help with upload ..



    Can anyone see why Im lossing the image type when it's renamed !

    Thanks
    Chris

    <?
    session_start() ;
    $n=$_FILES['user_file']['name'];
    $type=$_FILES['user_file']['type'];
    $size=$_FILES['user_file']['size'];
    $time=time();
    $n=$time;
    $path="uploads\ \". $n;
    $uploaded = $_SESSION['firsttimeuploa d'];
    if ($uploaded == "ok")
    {
    if ($size <900000 && ereg("image", $type ))
    {
    move_uploaded_f ile($_FILES['user_file']['tmp_name']['type'],
    $path);
    $root= "http://uploads/";
    $path2=$root . $n;
    echo "<center>";
    echo "<h3>Your Image : </h3><a href=$path2>$pa th2</a><br /><br />";
    echo "<br>";
    echo "<img src=$path2 border='1'></img>";
    echo "<center>";
    $fp=fopen("link s.text", "at");
    fwrite($fp, $path2."\n");
    fclose($fp);
    session_destroy ();
    }
    }
    else
    {
    echo "File all ready uploaded";
    }

    if ($size>900000)
    {
    echo "ERROR <br /the image size is too big";
    }

    if (!ereg("image", $type) )
    {
    echo "ERROR <br /the file is not image<br />";
    }

    ?>


  • Jerry Stuckle

    #2
    Re: Help with upload ..

    Joker7 wrote:
    Can anyone see why Im lossing the image type when it's renamed !
    >
    Thanks
    Chris
    >
    <?
    session_start() ;
    $n=$_FILES['user_file']['name'];
    $type=$_FILES['user_file']['type'];
    $size=$_FILES['user_file']['size'];
    $time=time();
    $n=$time;
    $path="uploads\ \". $n;
    $uploaded = $_SESSION['firsttimeuploa d'];
    if ($uploaded == "ok")
    {
    if ($size <900000 && ereg("image", $type ))
    {
    move_uploaded_f ile($_FILES['user_file']['tmp_name']['type'],
    $path);
    $root= "http://uploads/";
    $path2=$root . $n;
    echo "<center>";
    echo "<h3>Your Image : </h3><a href=$path2>$pa th2</a><br /><br />";
    echo "<br>";
    echo "<img src=$path2 border='1'></img>";
    echo "<center>";
    $fp=fopen("link s.text", "at");
    fwrite($fp, $path2."\n");
    fclose($fp);
    session_destroy ();
    }
    }
    else
    {
    echo "File all ready uploaded";
    }
    >
    if ($size>900000)
    {
    echo "ERROR <br /the image size is too big";
    }
    >
    if (!ereg("image", $type) )
    {
    echo "ERROR <br /the file is not image<br />";
    }
    >
    ?>
    >
    >
    What are you expecting in $_FILES['user_file']['tmp_name']['type']?
    There is no such array element. You do have
    $_FILES['user_file']['tmp_name'] and $_FILES['user_file']['type'].

    Also, NEVER depend on the 'type' value - if it is sent, it may or may
    not be accurate. ALWAYS check the mimetype of the file on the server.
    Check out exif_imagetype( ).

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • macca

      #3
      Re: Help with upload ..

      I agree with jerry, dont use the ['type'] value to determine the image
      type as it can not be relied upon. I do however find that
      getImageSize() is quite useful for this purpose.

      if(is_uploaded_ file($_FILES[$form_fieldname]['tmp_name'])){

      $img_mime_type = getimagesize($_ FILES[$form_fieldname]
      ['tmp_name']);

      if(($img_mime_t ype[2] == IMAGETYPE_GIF) ||
      ($img_mime_type[2] == IMAGETYPE_JPEG) ||
      ($img_mime_type[2] == IMAGETYPE_PNG))
      {
      ...
      }

      Comment

      Working...