I am using the jQuery-File-Upload for the first time.
http://blueimp.github.io/jQuery-File-Upload/basic.html
The file upload is contained inside a form that has other input fields.
When the form is submitted I would simply like to collect the name of the files that have been uploaded and perhaps location.
I am collecting the other variables like so,
if(isset($_GET['sub_btn'])){
$first_name = isset($_GET["firstname"]) ? $_GET["firstname"] : "";
}
But I cannot get the files that are uploaded to the server/php/files folder to appear in the $_GET or the $_POST.
Am I missing something?
The $.FILES
array should contain what you're searching for.
if you want to get the file on the server and set the date via POSt u can get them with $_FILES
and not with POST or GET
Tiny example:
<?php
$output_dir = "uploads/";
if(isset($_FILES["myfile"]))
{
$ret = array();
$error =$_FILES["myfile"]["error"];
//You need to handle both cases
//If Any browser does not support serializing of multiple files using FormData()
if(!is_array($_FILES["myfile"]["name"])) //single file
{
$fileName = $_FILES["myfile"]["name"];
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir.$fileName);
$ret[]= $fileName;
}
else //Multiple files, file[]
{
$fileCount = count($_FILES["myfile"]["name"]);
for($i=0; $i < $fileCount; $i++)
{
$fileName = $_FILES["myfile"]["name"][$i];
move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName);
$ret[]= $fileName;
}
}
echo json_encode($ret);
}
?>
JS:
$("#multipleupload").uploadFile({
url:"http://hayageek.com/examples/jquery/ajax-multiple-file-upload/upload.php",
multiple:true,
fileName:"myfile"
});
Thanks for the help guys, I actually found a solution here.