multiple image upload help
Results 1 to 6 of 6

Thread: multiple image upload help

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    19

    Unhappy multiple image upload help

    this script works fine, uploads multiple images and writes them to the db. but how can I restrict it to just images. I have been googleing since last night and seen hundreds of examples and still cant seem to grasp the concept. someone please help. the code I have is:

    PHP Code:
    function findexts ($filename) { $filename strtolower('$filename') ; 
    $exts preg_split("[/\\.]"$filename) ;
     
    $n count($exts)-1
     
    $exts $exts[$n];
      return 
    $exts;
       }
       
    $ext findexts ($_FILES['images']['name']) ; 
    $ran rand ();
    $ran2 $ran.".";
        
    while(list(
    $key,$value) = each($_FILES['images']['name']))
            {
                if(!empty(
    $value))
                {
                    
    $filename $ran.$value;
                        
    $filename=str_replace(" "," _ ",$filename);// Add _ inplace of blank space in file name, you can remove this line
                        
                        
    $the_dir 'media/'.$ad_id;
                        if(!
    file_exists($the_dir)) 
                            {
    mkdir($the_dir0700);}

                       
    $add $the_dir."/".$ran."$filename";
                    
    $insert_query "MYSQL INSERT STATEMENT";
                           
    //echo $_FILES['images']['type'][$key];
                     // echo "<br>";
                        
    copy($_FILES['images']['tmp_name'][$key], $add);
                        
    chmod("$add",0777);

            
    mysql_query($insert_query);
            
                }
                
            } 
    file fields are

    HTML Code:
    <input type='file' name='images[]'>
    <input type='file' name='images[]'>
    <input type='file' name='images[]'>
    <input type='file' name='images[]'>
    <input type='file' name='images[]'>

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,349
    The first thing you need to do is figure what you mean by "just images." What's an image? Is it any file that has a file extension that matches some common image formats? Is it a file that contains binary data you can actually parse as an image file?

    For the former, you'd simply use something like pathinfo() to grab the file extension and perhaps something like in_array() to compare it with an array of known "good" values.

    For the latter, you might try using something like getimagesize() to see if PHP can parse the binary contents of the file as an image.

  3. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    file extentions. I want to make sure users are only uploading png, gif and jpg images

  4. #4
    Junior Member
    Join Date
    Jul 2011
    Posts
    19
    also, I seen tons of ways on how to do it, I just cant figure out how to incorporate any of them into my script. im not exactly a php expert I'm just tired of people uploading crap

  5. #5
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,771
    See bradgrafelman's post.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  6. #6
    newbie php developer Damian_'s Avatar
    Join Date
    Jun 2011
    Location
    london
    Posts
    93
    Hi i think you will find this page very interesting:


    http://www.php.net/manual/en/functio...-extension.php

    and this:

    http://www.bitrepository.com/how-to-...ge-upload.html

    you will need to do a check on the image type "image_type_to_extension"

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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