Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post

    Multiple image upload script

    Hello,

    Looking for a simple php multiple upload script for images. Do you happen to have any?

    Found this script via googe:

    PHP Code:
    <?
        
    while(list($key,$value) = each($_FILES['images']['name']))
            {
                if(!empty(
    $value))
                {
                    
    $filename $value;
                        
    $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line

                        
    $add "upimg/$filename";
                           
    //echo $_FILES['images']['type'][$key];
                     // echo "<br>";
                        
    copy($_FILES['images']['tmp_name'][$key], $add);
                        
    chmod("$add",0777);
                

                }
            }


    ?>
    but it has one serious bug, it overwrites files with the same names... How can I fix that problem? Also I need to send the uploaded file path to the database...

    Can anyone please help?

    Thanks in advance

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Try
    PHP Code:
    $filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line

    while(file_exists('upimg/'.$filename))
      
    $filename=rand(1,9999).$filename;
    $add "upimg/$filename"
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder levani's Avatar
    Join Date
    Mar 2009
    Location
    Georgia
    Posts
    183
    Thanks
    29
    Thanked 1 Time in 1 Post
    Thanks for help, works fine. And the last question, where should I add the mysql insert query to insert the file name into the database if the file is uploaded... How should I get the uploaded file name for this purpose?

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    PHP Code:
    echo $filename
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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