如何允许用户同时使用文字输入创建文件夹导演名称和上传多张图片。 我使用http://www.phpgang.com/how-to-upload-multiple-images-jquery-ajax-using-php_453.html和简单的PHP代码来创建导演但我无法通过 jquery.fileuploadmulti.min 或<传递文件夹文件夹导演名称强> jquery.form 即可。检查下面的upload.php代码
require 'dbconnection.php';
//The name of the directory that we need to create.
$directoryName = $_POST['folder'];
//Check if the directory already exists.
if(!is_dir($directoryName)){
//Directory does not exist, so lets create it.
mkdir('imageFolder/'.$directoryName, 0755);
}
$output_dir = 'imageFolder/'.$directoryName.'/';
if(isset($_FILES["myfile"]))
{
$ret = array();
$error =$_FILES["myfile"]["error"];
{
if(!is_array($_FILES["myfile"]['name'])) //single file
{
$RandomNum = time();
$ImageName = str_replace(' ','-',strtolower($_FILES['myfile']['name']));
$ImageType = $_FILES['myfile']['type']; //"image/png", image/jpeg etc.
$ImageExt = substr($ImageName, strrpos($ImageName, '.'));
$ImageExt = str_replace('.','',$ImageExt);
$ImageName = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
$NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;
$url = "$output_dir$NewImageName";
move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $NewImageName);
//echo "<br> Error: ".$_FILES["myfile"]["error"];
mysql_query("INSERT INTO pictures(picture,url,name,folder) VALUES('$NewImageName','$output_dir$NewImageName','','$output_dir')") or die(mysql_error());
$ret[$fileName]= $output_dir.$NewImageName;
}
else
{
$fileCount = count($_FILES["myfile"]['name']);
for($i=0; $i < $fileCount; $i++)
{
$RandomNum = time();
$ImageName = str_replace(' ','-',strtolower($_FILES['myfile']['name'][$i]));
$ImageType = $_FILES['myfile']['type'][$i]; //"image/png", image/jpeg etc.
$ImageExt = substr($ImageName, strrpos($ImageName, '.'));
$ImageExt = str_replace('.','',$ImageExt);
$ImageName = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
$NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;
$ret[$NewImageName]= $output_dir.$NewImageName;
move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$NewImageName );
mysql_query("INSERT INTO pictures(picture,url,name,folder) VALUES('$NewImageName','$output_dir$NewImageName','','$output_dir')") or die(mysql_error());
}
}
}
echo json_encode($ret);
}