Jump to content

Multi File Upload


SkyRanger

Recommended Posts

Can somebody point me in the right direction. I am trying to create a multi file upload script with data stored in database. I can upload single file that is not a problem. But I need to figure out how to upload multiple files.

 

Database is:

 

Description pdfversion picversion zipversion

 

So the user puts in the description then added what ever version they want and it submits into the right column.

 

So the user adds a description then wants to upload a pdf and zip version and when he submits it goes into the right columns and uploads to the directory.

 

Any direction would be greatly appreciated.

Link to comment
Share on other sites

Thanks jazzman.

 

Got it so far to upload the files, but having problems with database entry.

 

Here is the code:

 

$compname=$_POST['icompname'];
$ipolicy=$_POST['polnum'];
$itofins=$_POST['tofins'];
$tstart=$_POST['cstart'];
$tend=$_POST['cend'];
$client=$_POST['member'];


$target = "clients/$client/insurance/";


// use static values in that case
$itype1= basename($_FILES['photo']['name'][0]);
$itype2= basename($_FILES['photo']['name'][1]);
$itype3= basename($_FILES['photo']['name'][2]);


if(!empty($_FILES['photo']['tmp_name']))
{


        // prepare insert query statement
        $query = "INSERT INTO cinsurh VALUES ('', '$client', '$compname', '$ipolicy', '$itofins', '$tstart', '$tend', '$itype1', '$itype2', '$itype3')";


        // Number of uploaded files
        $num_files = count($_FILES['photo']['tmp_name']);


        /** loop through the array of files ***/
        for($i=0; $i < $num_files;$i++)
        {
                // check if there is a file in the array
                if(!is_uploaded_file($_FILES['photo']['tmp_name'][$i]))
                {
                        $messages[] = 'No file uploaded';
                }
                else
                {
                        // move the file to the specified dir
                        if(move_uploaded_file($_FILES['photo']['tmp_name'][$i],$target.'/'.$_FILES['photo']['name'][$i]))
                        {

                                $messages[] = $_FILES['photo']['name'][$i].' uploaded';

                        }
                        else
                        {
                                // an error message
                                $messages[] = 'Uploading '.$_FILES['photo']['name'][$i].' Failed';
                        }
                }
        }

        echo '<pre>'.print_r($query, true).'</pre>';

        echo '<pre>'.print_r($messages, 1).'</pre>';


        // execute query...
        $result = $mysql->query($query) or die($mysqli->error.__LINE__);

}

 

But I am getting this error:

Fatal error: Call to a member function query() on a non-object in insert_policy.php on line 61

This is line 61:    $result = $mysql->query($query) or die($mysqli->error.__LINE__);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.