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 15 of 15

Thread: Multi Upload

  1. #1
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post

    Multi Upload

    Hey,

    I have recently coded a fully functional image hosting script (first php project for me...) but it's only single upload!

    Can anyone tell me what I need to do to make it multi upload please?

    index.php:
    Code:
    <font size="1"><b>Select file to upload: </b></font><input name="image" type="file" size="60" class="upload">
     <p align=center><input name="Submit" type="submit" value="Upload" class="button" onclick = 'this.style.display = "none"; document.getElementById("loading1").style.display = ""' />
    <img src = 'images/loading.gif' border = '0' alt = 'Loading' id = 'loading1' style = 'display: none;'/><br /><br />
    upload.php:
    PHP Code:
    <?php
     define 
    ("MAX_SIZE","1048576000"); 

     include(
    "config.php");

     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;
    //checks if the form has been submitted
     
    if(isset($_POST['Submit'])) 
     {
         
    //reads the name of the file the user submitted for uploading
         
    $image=$_FILES['image']['name'];
         
    //if it is not empty
         
    if ($image
         {
         
    //get the original name of the file from the clients machine
             
    $filename stripslashes($_FILES['image']['name']);
         
    //get the extension of the file in a lower case format
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
         
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
        //otherwise we will do more tests
    $typesallowed = array("jpg""jpeg""JPG""JPEG""pdf""png""txt""zip""bmp""gif""css");
    if (!
    in_array("$extension"$typesallowed)) 
            {
            
    //print error message
                 
    echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>'
    ;
                 
    $errors=1;
             }
             else
             {

     
    $size=filesize($_FILES['image']['tmp_name']);

    //compare the size with the maxim size we defined and print error if bigger
    if ($size MAX_SIZE*1048576000)
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>'
    ;
        
    $errors=1;
    }

    //we will give an unique name, for example the time in unix time format
    $max_filename_chars 5;
    function 
    getUniqueCode($length "8")
    {    
        
    $code md5(uniqid(rand(), true));
        if (
    $length != "") return substr($code0$length);
        else return 
    $code;
    }

    $image_name=getUniqueCode().'.'.$extension;
    $mymymy substr($image_name5);
    $newname="1/".$mymymy;
    //we verify if the image has been uploaded, and print error instead
    $copied copy($_FILES['image']['tmp_name'], $newname);
    if (!
    $copied
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>'
    ;
        
    $errors=1;
    }}}}

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {
         echo 
    "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
         echo 
    "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
    $types = array("txt""pdf""zip");
    if (
    in_array("$extension"$types)) {
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>"

    } else {
         echo 
    "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=[img]";
         echo 
    "http://jameskealey.po.gs/pick/";
         echo 
    $newname;
         echo 
    "[/img] style=width:45%><br>";
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
    $info=getimagesize("$newname");
    // display image details (only shown for images...)
    echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
    echo 
    "Image type: ".$info[mime]."<br />";
    echo 
    "Image size: ".$info[bits]." kB<br />";
    echo 
    "</font>";
    }



    $ip getenv("REMOTE_ADDR");
    include(
    'config.php');
    $link=mysql_connect($data_server$data_user$data_pw);
    mysql_select_db("jkealey");
    mysql_query("INSERT INTO image_table 
    (image, ip) VALUES('$newname', '$ip' ) "

    or die(
    mysql_error());  

     }

     
    ?>
    Any help would be appriciated. I can't find a way to do multi upload. I don't want to use two different scripts etc...

    James
    Last edited by jamesk; 02-27-2010 at 10:05 PM.

  • #2
    New to the CF scene
    Join Date
    Feb 2010
    Location
    Texas
    Posts
    8
    Thanks
    0
    Thanked 3 Times in 3 Posts
    change the html to have two(or more) input tags:
    Code:
    Upload 1: <input name="file_upload[0]" type="file" size="25"/><br>
    Upload 2: <input name="file_upload[1]" type="file" size="25"/><br>
    Then if the user uploads two, the $_FILES superglobal will have another dimension, so:
    PHP Code:
    if(is_array($_FILES['file_upload']['name'])) {
        foreach(
    $_FILES['file_upload']['name'] as $i=>$unused) {
            
    $extraDigit = (($i==0) ? '':$i+1);
            if(
    file_exists($_FILES['file_upload']['tmp_name'][$i])) {
                
    handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
            }
        }
    } else {
        if((isset(
    $_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
            
    handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
        }


  • #3
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    Ok, thanks very much - but where does that go in my code?

    can you possible put it in the code for me? and then how would i get the amount of input fields to display the links at the bottom?

    Understand me? Sorry if i seem a little vague!

    PM me if you are unsure

    James

  • #4
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    Can anyone tell me where to put:

    PHP Code:
    if(is_array($_FILES['file_upload']['name'])) {
        foreach(
    $_FILES['file_upload']['name'] as $i=>$unused) {
            
    $extraDigit = (($i==0) ? '':$i+1);
            if(
    file_exists($_FILES['file_upload']['tmp_name'][$i])) {
                
    handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
            }
        }
    } else {
        if((isset(
    $_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
            
    handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
        }

    in my original script? I can't seem to get it to work.

    Any help would be fantastic.

    Cheers,
    James

  • #5
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    I would really like this script to work - can anyone please help.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Okay so WHAT have you tried? We are here to help but we aren't here to just code for you. Show us that you actually tried to do yourself and we can tell you where you went wrong. If aren't willing to do that then I suggest you hire a professional.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    I have tried to place the code in several different places, and I can't get it to upload the images correctly.

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Then post the code you tried to use.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #9
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    If possible, I would like to know where to put:

    PHP Code:
    if(is_array($_FILES['file_upload']['name'])) {
        foreach(
    $_FILES['file_upload']['name'] as $i=>$unused) {
            
    $extraDigit = (($i==0) ? '':$i+1);
            if(
    file_exists($_FILES['file_upload']['tmp_name'][$i])) {
                
    handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
            }
        }
    } else {
        if((isset(
    $_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
            
    handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
        }

    in:

    PHP Code:
    <?php
     define 
    ("MAX_SIZE","1048576000"); 

     include(
    "config.php");

     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;
    //checks if the form has been submitted
     
    if(isset($_POST['Submit'])) 
     {
         
    //reads the name of the file the user submitted for uploading
         
    $image=$_FILES['image']['name'];
         
    //if it is not empty
         
    if ($image
         {
         
    //get the original name of the file from the clients machine
             
    $filename stripslashes($_FILES['image']['name']);
         
    //get the extension of the file in a lower case format
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
         
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
        //otherwise we will do more tests
    $typesallowed = array("jpg""jpeg""JPG""JPEG""pdf""png""txt""zip""bmp""gif""css");
    if (!
    in_array("$extension"$typesallowed)) 
            {
            
    //print error message
                 
    echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>'
    ;
                 
    $errors=1;
             }
             else
             {

     
    $size=filesize($_FILES['image']['tmp_name']);

    //compare the size with the maxim size we defined and print error if bigger
    if ($size MAX_SIZE*1048576000)
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>'
    ;
        
    $errors=1;
    }

    //we will give an unique name, for example the time in unix time format
    $max_filename_chars 5;
    function 
    getUniqueCode($length "8")
    {    
        
    $code md5(uniqid(rand(), true));
        if (
    $length != "") return substr($code0$length);
        else return 
    $code;
    }

    $image_name=getUniqueCode().'.'.$extension;
    $mymymy substr($image_name5);
    $newname="1/".$mymymy;
    //we verify if the image has been uploaded, and print error instead
    $copied copy($_FILES['image']['tmp_name'], $newname);
    if (!
    $copied
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>'
    ;
        
    $errors=1;
    }}}}

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {
         echo 
    "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
         echo 
    "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
    $types = array("txt""pdf""zip");
    if (
    in_array("$extension"$types)) {
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>"

    } else {
         echo 
    "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=[img]";
         echo 
    "http://jameskealey.po.gs/pick/";
         echo 
    $newname;
         echo 
    "[/img] style=width:45%><br>";
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
    $info=getimagesize("$newname");
    // display image details (only shown for images...)
    echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
    echo 
    "Image type: ".$info[mime]."<br />";
    echo 
    "Image size: ".$info[bits]." kB<br />";
    echo 
    "</font>";
    }



    $ip getenv("REMOTE_ADDR");
    include(
    'config.php');
    $link=mysql_connect($data_server$data_user$data_pw);
    mysql_select_db("jkealey");
    mysql_query("INSERT INTO image_table 
    (image, ip) VALUES('$newname', '$ip' ) "

    or die(
    mysql_error());  

     }

     
    ?>
    To allow the user to upload more than one file. Also, how would I show the links for the second file that was uploaded on the upload.php page?

    James

  • #10
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You aren't getting what I'm asking you. Try to put the code that was given to you inside of your existing code and then post exactly what you tried.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #11
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    PHP Code:
    <?php
     define 
    ("MAX_SIZE","1048576000"); 

     include(
    "config.php");

     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;
    //checks if the form has been submitted
     
    if(isset($_POST['Submit'])) 
     {
         
    //reads the name of the file the user submitted for uploading
         
    $image=$_FILES['image']['name'];
         
    //if it is not empty
         
    if ($image
         {
         
    //get the original name of the file from the clients machine
             
    $filename stripslashes($_FILES['image']['name']);
         
    //get the extension of the file in a lower case format
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
         
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
        //otherwise we will do more tests
    $typesallowed = array("jpg""jpeg""JPG""JPEG""pdf""png""txt""zip""bmp""gif""css");
    if (!
    in_array("$extension"$typesallowed)) 
            {
            
    //print error message
                 
    echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>'
    ;
                 
    $errors=1;
             }
             else
             {

     
    $size=filesize($_FILES['image']['tmp_name']);

    //compare the size with the maxim size we defined and print error if bigger
    if ($size MAX_SIZE*1048576000)
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>'
    ;
        
    $errors=1;
    }

    //we will give an unique name, for example the time in unix time format
    $max_filename_chars 5;
    function 
    getUniqueCode($length "8")
    {    
        
    $code md5(uniqid(rand(), true));
        if (
    $length != "") return substr($code0$length);
        else return 
    $code;
    }

    $image_name=getUniqueCode().'.'.$extension;
    $mymymy substr($image_name5);
    $newname="1/".$mymymy;
    //we verify if the image has been uploaded, and print error instead
    $copied copy($_FILES['image']['tmp_name'], $newname);
    if (!
    $copied
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>'
    ;
        
    $errors=1;
    }}}}

    if(
    is_array($_FILES['file_upload']['name'])) {
        foreach(
    $_FILES['file_upload']['name'] as $i=>$unused) {
            
    $extraDigit = (($i==0) ? '':$i+1);
            if(
    file_exists($_FILES['file_upload']['tmp_name'][$i])) {
                
    handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
            }
        }
    } else {
        if((isset(
    $_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
            
    handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
        }


    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {
         echo 
    "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
         echo 
    "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
    $types = array("txt""pdf""zip");
    if (
    in_array("$extension"$types)) {
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>"

    } else {
         echo 
    "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=[img]";
         echo 
    "http://jameskealey.po.gs/pick/";
         echo 
    $newname;
         echo 
    "[/img] style=width:45%><br>";
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
    $info=getimagesize("$newname");
    // display image details (only shown for images...)
    echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
    echo 
    "Image type: ".$info[mime]."<br />";
    echo 
    "Image size: ".$info[bits]." kB<br />";
    echo 
    "</font>";
    }



    $ip getenv("REMOTE_ADDR");
    include(
    'config.php');
    $link=mysql_connect($data_server$data_user$data_pw);
    mysql_select_db("jkealey");
    mysql_query("INSERT INTO image_table 
    (image, ip) VALUES('$newname', '$ip' ) "

    or die(
    mysql_error());  

     }

     
    ?>

  • #12
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    Any more help on this please? I understand I'm asking a lot...

    James

  • #13
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    I do apolagise about this - I am asking is someone can tell me what do to this script:

    PHP Code:
    <?php
     define 
    ("MAX_SIZE","1048576000"); 

     include(
    "config.php");

     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;
    //checks if the form has been submitted
     
    if(isset($_POST['Submit'])) 
     {
         
    //reads the name of the file the user submitted for uploading
         
    $image=$_FILES['image']['name'];
         
    //if it is not empty
         
    if ($image
         {
         
    //get the original name of the file from the clients machine
             
    $filename stripslashes($_FILES['image']['name']);
         
    //get the extension of the file in a lower case format
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
         
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
        //otherwise we will do more tests
    $typesallowed = array("jpg""jpeg""JPG""JPEG""pdf""png""txt""zip""bmp""gif""css");
    if (!
    in_array("$extension"$typesallowed)) 
            {
            
    //print error message
                 
    echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>'
    ;
                 
    $errors=1;
             }
             else
             {

     
    $size=filesize($_FILES['image']['tmp_name']);

    //compare the size with the maxim size we defined and print error if bigger
    if ($size MAX_SIZE*1048576000)
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>'
    ;
        
    $errors=1;
    }

    //we will give an unique name, for example the time in unix time format
    $max_filename_chars 5;
    function 
    getUniqueCode($length "8")
    {    
        
    $code md5(uniqid(rand(), true));
        if (
    $length != "") return substr($code0$length);
        else return 
    $code;
    }

    $image_name=getUniqueCode().'.'.$extension;
    $mymymy substr($image_name5);
    $newname="1/".$mymymy;
    //we verify if the image has been uploaded, and print error instead
    $copied copy($_FILES['image']['tmp_name'], $newname);
    if (!
    $copied
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>'
    ;
        
    $errors=1;
    }}}}

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {
         echo 
    "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
         echo 
    "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
    $types = array("txt""pdf""zip");
    if (
    in_array("$extension"$types)) {
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>"

    } else {
         echo 
    "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=[img]";
         echo 
    "http://jameskealey.po.gs/pick/";
         echo 
    $newname;
         echo 
    "[/img] style=width:45%><br>";
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
    $info=getimagesize("$newname");
    // display image details (only shown for images...)
    echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
    echo 
    "Image type: ".$info[mime]."<br />";
    echo 
    "Image size: ".$info[bits]." kB<br />";
    echo 
    "</font>";
    }



    $ip getenv("REMOTE_ADDR");
    include(
    'config.php');
    $link=mysql_connect($data_server$data_user$data_pw);
    mysql_select_db("jkealey");
    mysql_query("INSERT INTO image_table 
    (image, ip) VALUES('$newname', '$ip' ) "

    or die(
    mysql_error());  

     }

     
    ?>
    To make it multi upload. Someone has already given me:

    PHP Code:
    if(is_array($_FILES['file_upload']['name'])) {
        foreach(
    $_FILES['file_upload']['name'] as $i=>$unused) {
            
    $extraDigit = (($i==0) ? '':$i+1);
            if(
    file_exists($_FILES['file_upload']['tmp_name'][$i])) {
                
    handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
            }
        }
    } else {
        if((isset(
    $_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
            
    handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
        }

    and told me to change my original index.php page to:
    PHP Code:
    Upload 1: <input name="file_upload[0]" type="file" size="25"/><br>
    Upload 2: <input name="file_upload[1]" type="file" size="25"/><br
    but everywhere I put that code to allow the multi upload - it either doesn't work or i get errors!

    Any help? I will give FTP access to people if required.

    I hope someone can help me here, I'm so close I think :P...

    James

  • #14
    New Coder
    Join Date
    Apr 2009
    Location
    UK
    Posts
    56
    Thanks
    5
    Thanked 1 Time in 1 Post
    Sorry for bumping this 2 months later, but I still can't get it to work.

    This my simple upload script:
    PHP Code:
    <?php
     define 
    ("MAX_SIZE","1048576000"); 

     include(
    "config.php");

     function 
    getExtension($str) {
             
    $i strrpos($str,".");
             if (!
    $i) { return ""; }
             
    $l strlen($str) - $i;
             
    $ext substr($str,$i+1,$l);
             return 
    $ext;
     }

     
    $errors=0;
    //checks if the form has been submitted
     
    if(isset($_POST['Submit'])) 
     {
         
    //reads the name of the file the user submitted for uploading
         
    $image=$_FILES['image']['name'];
         
    //if it is not empty
         
    if ($image
         {
         
    //get the original name of the file from the clients machine
             
    $filename stripslashes($_FILES['image']['name']);
         
    //get the extension of the file in a lower case format
              
    $extension getExtension($filename);
             
    $extension strtolower($extension);
         
    //if it is not a known extension, we will suppose it is an error and will not  upload the file,  
        //otherwise we will do more tests
    $typesallowed = array("jpg""jpeg""JPG""JPEG""pdf""png""txt""zip""bmp""gif""css");
    if (!
    in_array("$extension"$typesallowed)) 
            {
            
    //print error message
                 
    echo '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have tried to upload an invalid extension! Please try again!</font>'
    ;
                 
    $errors=1;
             }
             else
             {

     
    $size=filesize($_FILES['image']['tmp_name']);

    //compare the size with the maxim size we defined and print error if bigger
    if ($size MAX_SIZE*1048576000)
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>You have exceeded the file upload limit! Please upload a smaller image.</font>'
    ;
        
    $errors=1;
    }

    //we will give an unique name, for example the time in unix time format
    $max_filename_chars 5;
    function 
    getUniqueCode($length "8")
    {    
        
    $code md5(uniqid(rand(), true));
        if (
    $length != "") return substr($code0$length);
        else return 
    $code;
    }

    $image_name=getUniqueCode().'.'.$extension;
    $mymymy substr($image_name5);
    $newname="1/".$mymymy;
    //we verify if the image has been uploaded, and print error instead
    $copied copy($_FILES['image']['tmp_name'], $newname);
    if (!
    $copied
    {
        echo 
    '<font face=verdana size=2 color=red><b>Error!</font></b><br>
    <font face=verdana size=1 color=black>Upload unsuccessful. Either you did not select an image to upload or there has been another error.</font>'
    ;
        
    $errors=1;
    }}}}

    //If no errors registred, print the success message
     
    if(isset($_POST['Submit']) && !$errors
     {
         echo 
    "<p align=center><font face=verdana size=4><b><a href=$newname>View your Upload</a></font><br /<br />";
         echo 
    "<b><font face=verdana size=1>File Link:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input value=http://jameskealey.po.gs/pick/$newname style= width:45% class='bx' onclick='this.select()'><br \><br \>";
    $types = array("txt""pdf""zip");
    if (
    in_array("$extension"$types)) {
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http:////twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></font></p>"

    } else {
         echo 
    "<b>UBBC Code:</b></font><input class='bx' onclick='this.select()' value=[img]";
         echo 
    "http://jameskealey.po.gs/pick/";
         echo 
    $newname;
         echo 
    "[/img] style=width:45%><br>";
        echo 
    "<font face=verdana size=1><a href=index.php>[Upload Another File]</a></font><br>";
        echo 
    "<font face=verdana size=1><a href=http://twitter.com/home?status=jameskealey.po.gs/pick/$newname%20-%20Look%20at%20my%20file!>Tweet File</a></p></b>";
    $info=getimagesize("$newname");
    // display image details (only shown for images...)
    echo "Dimensions: ".$info[0]." x ".$info[1]."<br />";
    echo 
    "Image type: ".$info[mime]."<br />";
    echo 
    "Image size: ".$info[bits]." kB<br />";
    echo 
    "</font>";
    }



    $ip getenv("REMOTE_ADDR");
    include(
    'config.php');
    $link=mysql_connect($data_server$data_user$data_pw);
    mysql_select_db("jkealey");
    mysql_query("INSERT INTO image_table 
    (image, ip) VALUES('$newname', '$ip' ) "

    or die(
    mysql_error());  

     }

     
    ?>
    To make it multi-upload, I need to put:
    PHP Code:
    if(is_array($_FILES['file_upload']['name'])) {
        foreach(
    $_FILES['file_upload']['name'] as $i=>$unused) {
            
    $extraDigit = (($i==0) ? '':$i+1);
            if(
    file_exists($_FILES['file_upload']['tmp_name'][$i])) {
                
    handleUploadFile($_FILES['file_upload']['tmp_name'][$i],$_FILES['file_upload']['name'][$i]);
            }
        }
    } else {
        if((isset(
    $_FILES['file_upload'])) && ($_FILES['file_upload']['name']) && ($_FILES['file_upload']['tmp_name'] != 'none')) {
            
    handleUploadFile($_FILES['file_upload']['tmp_name'],$_FILES['file_upload']['name']);
        }

    somewhere - someone suggested this earlier.

    Also, I have now change index.php so it can accept multi uploads:
    PHP Code:
    Upload 1: <input name="file_upload[0]" type="file" size="25"/><br>
    Upload 2: <input name="file_upload[1]" type="file" size="25"/><br
    but everywhere I put that code to allow the multi upload - it either doesn't work or i get errors!

    Any help? I will give FTP access to people if required.


    James

  • #15
    New Coder
    Join Date
    Jul 2008
    Posts
    91
    Thanks
    4
    Thanked 9 Times in 9 Posts
    Hey, PM me and i'll re-code it for you.
    Current Project: Nothing at the minute


  •  

    Posting Permissions

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