Uploader issue : would the uploader specify names ?

Discussion in 'PHP' started by Alison3011, Aug 21, 2012.

  1. #1
    hello, i'm working on this project and one of the pages is a php multi uploader with html5 form
    when the users upload a file, the uploader saves them in their original name
    and i want the (uploader) to change the names of the (uploaded files) with a [names that i specify in the code]
    is that possible ?? with the arrays may be ??

    this is the code:

    
    
    <?
    if (isset ($_FILES['files']))
    {
        foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name){
            move_uploaded_file($tmp_name, "images/{$_FILES['files']['name'][$key]}");}
    }
    
    ?>
    
    <!DOCTYPE HTML>
    <html>
    <head>
        <meta http-equiv="vontent-type" contents="text/html; charset=utf-8">
        <head></head>
        <body>
            <div id=formelements>
                <form action="" method="post" enctype="multipart/form-data">
                    <input type="file" name="files[]" multiple="multiple" min="12" max="999999"  />
                    <input type="submit" value="upload" />
                </form>
            </div>
        </body>
        </html>
    
    PHP:


    Alison,
    p.s: this is a multi uploader
     
    Alison3011, Aug 21, 2012 IP
  2. wwwprog

    wwwprog Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    It works!
    
    <?
    if (isset ($_FILES['files']))
    {
        $_FILES['files'];
        foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name){
            $tmp_name = $_FILES['files']['tmp_name'][$key];
            $sn = explode('.',$_FILES['files']['name'][$key]);
            //Rename
            $ran = rand(100,200);
            move_uploaded_file($tmp_name, "./images/$ran.{$sn['1']}");}
    }
    ?>
    
    PHP:
     
    wwwprog, Aug 22, 2012 IP