Before I implemented the daabase aspect of this, I was able to upload four files at a time,
and view their $_FILES data just on the screen, but I ran into a little bit of a snag here.
when I'm uploading multiple files,
they may all be associated with one comment/note,
and there may not be 4, it could be 1, 2, 3, or 4.
So if i run the entire query for each file, like this:
foreach( $_FILES as $file_name => $file_array ) {
if(move_uploaded_file( $file_array['tmp_name'], $file_dir.'/'.$file_array['name'] )) {
$query = "INSERT INTO notes ( clientid, topic, date, comment, report1, file1, path1,
report2, file2, path2, report3, file3, path3, report4, file4, path4 )
VALUES( '$id', '$topic', '$date', '$comment', '$report1', '$file1', '$path1', '$report2',
'$file2', '$path2', '$report3', '$file3', '$path3', '$report4', '$file4', '$path4' )";
if( ! mysql_query( $query, $link ) ) {
die("Could not execute query: ".mysql_error());
}
}
else {
die("Couldn't Copy");
}
}
the comments and notes get all screwed up.
So, I'm guessing I need to just use the loop to build the query in pieces,
but I'm not totally sure how that would work.
I think it needs to look something like:
$path = $file_dir.'/';
foreach( $_FILES as $file_name => $file_array ) {
if( move_uploaded_file( $file_array['tmp_name'], $file_dir.'/'.$file_array['name'] ) ) {
if ( isset file1 ) {
$report1 = $report1; //from the form input
$file1 = $filearray['name'];
}
if ( isset file2 ) {
$report2 = $report2; //from the form input
$file2 = $filearray['name'];
}
if ( isset file3 ) {
$report3 = $report3; //from the form input
$file3 = $filearray['name'];
}
if ( isset file4 ) {
$report4 = $report4; //from the form input
$file4 = $filearray['name'];
}
if( ! mysql_query( $query, $link ) ) {
die("Could not execute query: ".mysql_error());
}
}
else {
die("Couldn't Copy");
}
}
$query = "INSERT INTO notes ( clientid, topic, date, comment, report1, file1, path1,
report2, file2, path2, report3, file3, path3, report4, file4, path4 )
VALUES( '$id', '$topic', '$date', '$comment', '$report1', '$file1', '$path', '$report2',
'$file2', '$path', '$report3', '$file3', '$path', '$report4', '$file4', '$path' )";
but i know thats not the way to do it. I hope this is really as complex as it seems to me. 😃
cuz i'm going to feel pretty silly if there's some really easy way to do all of this...
cheers all!
Jason