I'm working on an exercise in which users can upload multiple files at the same time, give them descriptions and then INSERT said files with descriptions into a mySQL table.
So far there is a successful user inter-face up and running (mostly used jQuery). Now I am trying to process the user input through PHP. Following is the applicable PHP script:
Code: Select all
<?php
// Array used to push/insert data
$merged_array=array();
// Arrays used to process files
$up_array=array();
$names_array=array();
$types_array=array();
$temp_array=array();
$desc_array = array();
// set up increment counter
$line_counter=-1;
if (!empty($_POST))
{
$desc_array=array("description"=>$_POST['descriptions']);
if (!empty($_FILES))
{
$up_array=$_FILES['uploads'];
$names_array=array("name"=>$up_array["name"]);
$types_array=array("type"=>$up_array["type"]);
$temp_array=array("temp"=>$up_array["tmp_name"]);
$merged_array = array_merge($names_array, $types_array, $temp_array, $desc_array);
$file_ct=count($names_array,1);
while ($line_counter < $file_ct-2) {
$line_counter++;
foreach($merged_array as $line) {
$file_name=$merged_array["name"];
$file_type=$merged_array["type"];
$file_temp=$merged_array["temp"];
$file_desc=$merged_array["description"];
echo $content;
} // end foreach
echo "Data packet: " . $file_name[$line_counter] . ", " . $file_type[$line_counter] . ", " . $file_temp[$line_counter] . ", " . $file_desc[$line_counter] . "<br />";
} // end while
}
}
?>As stated earlier, my main goal is to store these files (with descriptions) in a mySQL table. Storing file name, size, type is NOT the same thing as storing content. How do I attach the file content to a variable so that I can INSERT into mySQL?
Thanks in advance - Pavilion