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

Thread: Array Help

  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts

    Array Help

    How can you take the data from an array and seperate the information and post it to your database.??

    Thanks, S.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    What do you mean? Example?

  • #3
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    I am working on creating a multi upload script and would like to put the image name into the database along with other information from the form. it all works great .. the images upload.. I just want to add the image names to the database..??

    Form:
    PHP Code:
    <!doctype html public "-//w3c//dtd html 3.2//en">

    <html>

    <head>
    <title>Multiple image upload script</title>
    <meta name="GENERATOR" content="Arachnophilia 4.0">
    <meta name="FORMATTER" content="Arachnophilia 4.0">
    </head>

    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    <?
    $max_no_img
    =4;  // Maximum number of images value to be set here
    echo "<form method=post action=addimgck.php enctype='multipart/form-data'>";
    echo 
    "<table border='0' width='400' cellspacing='0' cellpadding='0' align=center>";
    for(
    $i=1$i<=$max_no_img$i++){
    echo 
    "<tr><td>Images $i</td><td>
        <input type=file name='images[]' class='bginput'></td></tr>"
    ;
    }
    echo 
    "<tr><td colspan=2 align=center><input type=submit value='Add Image'></td></tr>"

    echo 
    "</form> </table>";



    ?>


    </body>

    </html>

    Upload script
    PHP Code:
    <!doctype html public "-//w3c//dtd html 3.2//en">

    <html>

    <head>
    <title>Multiple image upload script</title>
    <meta name="GENERATOR" content="">
    <meta name="FORMATTER" content="">
    </head>

    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    <?
        
    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>";
                      
    echo "$filename";
                        
    copy($_FILES['images']['tmp_name'][$key], $add);
                        
    chmod("$add",0777);


                }

                    }

    ?>


    </body>

    </html>

    Thanks, S.

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    The images filename you mean? $filename above? And I assume a normalized database structure?

    Simply enough (how I would do it anyway)

    PHP Code:
    $insertQuery "INSERT INTO images (imgName) VALUES ";
    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>";
                       
    $insertQuery .= "('$filename'), ";
                      echo 
    "$filename";
                        
    copy($_FILES['images']['tmp_name'][$key], $add);
                        
    chmod("$add",0777);


                }

           }
    $insertQuery rtrim($insertQuery' ,'); 

  • #5
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    Thanks for your help...

    No I have not set the DB structure as of yet... I would love your input on that as well if you could.

    Thanks, S.

  • #6
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Well, hard to figure out what you're gonna insert if you don't know what you're inserting into

    If all you're storing is the image name, I'm not certain you need to store it into a db anyway. You could use glob to pick up all the images in a particular directory. What else do you plan on storing with the image?

  • #7
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    I a working on a post you rig type site..

    Where they post info and images of their PC and show off what they have.

    any help, suggestions etc. would be great.

    how would you go about using the glob idea.. never seen or tried it.?

    S.
    Last edited by SlayerACC; 07-01-2010 at 11:43 PM.

  • #8
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,536
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Glob is a function that pulls all the files in a perticular folder, and can do what I guess would be called rudimentary regex?

    http://net.tutsplus.com/tutorials/ph...ith-phps-glob/

  • Users who have thanked Keleth for this post:

    SlayerACC (07-02-2010)

  • #9
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    239
    Thanks
    47
    Thanked 3 Times in 3 Posts
    That is awesome... Thanks very much.

    S.


  •  

    Posting Permissions

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