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
https://forums.phpfreaks.com/topic/274905-multi-file-upload/
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
https://forums.phpfreaks.com/topic/274905-multi-file-upload/#findComment-1414912
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.