0

The HTML script below collects user information and files and posts to the database. the challenge is that when the files are multiple, it send the file path to different rows. please assist me to configure the upload file to send the file path for images per upload to one row. thank you.

HTML

Hotel Name * Town/City * "/> (+) Add file

Upload.php.

<?php
include ("connection.php");
if ($_POST["action"] == "Upload")
    die ("Error: no files uploaded!");

$file_count = count($_FILES["item_file"]['name']);

echo $file_count . " file(s) sent... <BR><BR>";

if(count($_FILES["item_file"]['name'])>0) { //check if any file uploaded

    for($j=0; $j < count($_FILES["item_file"]['name']); $j++) { //loop the uploaded file array

        $filen = $_FILES["item_file"]['name'][$j];  

        // ingore empty input fields
        if ($filen!="")
        {

            // destination path - you can choose any file name here (e.g. random)
            $path = "images/" . $filen; 

            if(move_uploaded_file($_FILES["item_file"]['tmp_name']["$j"],$path)) { 

            echo "File# ".($j+1)." ($filen) uploaded successfully!<br>"; 

            } else
            {
                echo  "Errors occoured during file upload!";
            }
            //create array of temporarily grab variables
            $input_arr=array();

            //grabs the post variables and adds slashes
            foreach($_POST as $key=> $input_arr){
                $_POST[$key]=addslashes($input_arr);
            }

            mysql_select_db("fcom_com") or die("Could not select database");
            mysql_query("INSERT INTO contri (field_1,field_2,URL)
                VALUES('".$_POST['field_1']."','".$_POST['field_2']."','".$_FILES['item_file']['name']["$j"]."')");
        }       
    }
}

?>

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.