PHP code, image hosting

Discussion in 'PHP' started by picking, Nov 16, 2006.

Thread Status:
Not open for further replies.
  1. #1
    Hello I need some help with these image hosting I'm trying to add multiple upload files options but I'm having trouble changing the code from single upload to various uploads, the outcome file index2.php has the code for the first usefile, i'm not sure if how to go about, i tried adding for a usefile1 and userfile2 but that doesn't work, any ideas, help. is greatly appreciated
     
    picking, Nov 16, 2006 IP
  2. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Look at the Uploading File Arrays section here:

    http://www.php.net/manual/en/features.file-upload.php

    If you need more specific help, you may need to post code samples of the HTML FORM you are using and how you are trying to parse it and what exactly is happening.
     
    ajscottsr, Nov 16, 2006 IP
    picking likes this.
  3. scribby

    scribby Active Member

    Messages:
    497
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    65
    #3
    Yes the PHP guide is the way to go.

    If you know your way around PHP its quite simple you have to set the name of the variable your sending as an array such as files[] then you can do what you normally do with your files but remember they are now in an array so you will need to separate an process each one individually.
     
    scribby, Nov 16, 2006 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  5. picking

    picking Peon

    Messages:
    501
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    thanks to all for the help, i've been trying things out but im having a complication since my code looks like this
    <form method="post" enctype="multipart/form-data" action="reg/index2.php">
    <INPUT TYPE="file" NAME="userfile[]" size="27" />
    <INPUT TYPE="file" NAME="userfile[]" size="27" />
    <INPUT TYPE="file" NAME="userfile[]" size="27" />

    <input type="submit" value="Upload" name="upload"/>
    </form>

    so I have to sort things out on the index2.php and I'm not sure how to go about to add the foreach code so that it works, any ideas?
     
    picking, Nov 16, 2006 IP
  6. picking

    picking Peon

    Messages:
    501
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    on the index2.php it starts like this
    <?
    include "config.php";

    if (!isset($HTTP_POST_FILES['userfile'])) exit;

    if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

    if ($HTTP_POST_FILES['userfile']['size']>$max_size) {
    echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">File is too big !</font><br>\n"; exit; }
    if(($HTTP_POST_FILES['userfile']['type']=="image/gif") ||
    ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg") ||
    ($HTTP_POST_FILES['userfile']['type']=="image/JPEG") ||
    ($HTTP_POST_FILES['userfile']['type']=="image/png")) {

    if (file_exists("./".$path . $HTTP_POST_FILES['userfile']['name'])) {
    echo "<font color=\"#333333\" face=\"Geneva, Arial, Helvetica, sans-serif\">There already exists a file with this name, please rename your file and try again</font><br>\n"; exit; }

    //generate random number
    $zufall = rand(1,9999);
    $fupl = "$zufall";

    keeps going with code to show the pictures
     
    picking, Nov 16, 2006 IP
  7. ajscottsr

    ajscottsr Peon

    Messages:
    388
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    0
    #7
    That's the problem right there. The code sample is assuming there is only 1 entry in the $HTTP_POST_FILES[] array.

    Look at the sample on php.net again. It uses a foreach statement to loop through each entry in the array. You will have to do it that way to be able to get to each different file that was uploaded.

    Hope that helps.
     
    ajscottsr, Nov 17, 2006 IP
Thread Status:
Not open for further replies.