Javascript 在PHP中上传多个图像
我必须上传多个图片到MySQL中,但是这段代码不能得到正确的输出。我怎样才能解决这个问题 这是我的代码:Javascript 在PHP中上传多个图像,javascript,php,Javascript,Php,我必须上传多个图片到MySQL中,但是这段代码不能得到正确的输出。我怎样才能解决这个问题 这是我的代码: $target_folder = "../tour-images/"; if ($_FILES['photo_url']['name']) { //echo "hii"; $allowable_extensions = array("image/jpg", "image/jpeg", "image/pjpeg", "image/png", "image/gif");
$target_folder = "../tour-images/";
if ($_FILES['photo_url']['name']) {
//echo "hii";
$allowable_extensions = array("image/jpg", "image/jpeg", "image/pjpeg", "image/png", "image/gif");
$imagename = $_FILES["photo_url"]["name"];
//echo "<br>hii".$imagename."<br>".$allowable_extensions;
$file_type = $_FILES["photo_url"]["type"];
print_r($file_type);
if (in_array($file_type, $allowable_extensions)) {
for($i = 0; $i < count($_FILES['file']['name']); $i++) {
//$file_ext = substr($file_type, 6);
$file_ext = explode('.', $file_type[$i]);
echo $file_ext;
$source = $_FILES["photo_url"]['tmp_name'];
$target1 = $target_folder . $imagename . "." . $file_ext;
echo "<br>" . $target1;
$photourl = $target_folder . $imagename . "." . $file_ext;
echo "hcxxxxxxx" . $photourl;
if (move_uploaded_file($source, $target1))
{
$filename11 = $target1;
}
}
}
}
else {
$filename = $target_folder . "noLogo.jpeg";
$photourl = "noLogo.jpeg";
}
$sql = "INSERT INTO image_details(tour_id,photo_url) VALUES('".$id."', '".$filename11."')";
mysql_query($sql);
echo $sql;
$target_folder=“../tour images/”;
如果($\u文件['photo\u url']['name'])){
//回声“hii”;
$allowed_extensions=数组(“image/jpg”、“image/jpeg”、“image/pjpeg”、“image/png”、“image/gif”);
$imagename=$\u文件[“照片url”][“名称”];
//echo“
hii”。$imagename。”
“$允许的扩展名;
$file\u type=$\u FILES[“photo\u url”][“type”];
打印(文件类型);
if(在数组中($file\u type,$allowed\u extensions)){
对于($i=0;$i”$target1;
$photourl=$target_folder.$imagename.“.”$file_ext;
echo“hcxxxxxxx”。$photourl;
如果(移动上传的文件($source$target1))
{
$filename11=$target1;
}
}
}
}
否则{
$filename=$target_文件夹。“noLogo.jpeg”;
$photourl=“noLogo.jpeg”;
}
$sql=“插入图像详细信息(巡更id、照片url)值(“$id.”、“$filename11.”);
mysql_查询($sql);
echo$sql;
尝试以下代码上载多个文件并存储在数据库中
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
<input type="text" name="Filename">
<input type="file" name="photo_url[]" multiple>
<input type="submit" value="Upload">
</form>
<?php
if (isset($_FILES['photo_url'])) {
$images = array();
$myFile = $_FILES['photo_url'];
$fileCount = count($myFile["name"]);
$Filename=$_POST['Filename'];
$structure = "Uploads/SystemConfiguration/$Filename";
if (!mkdir($structure, 0777, true))
{
die('Failed to create folders...');
}
for ($i = 0; $i < $fileCount; $i++) {
$name = $_FILES["photo_url"]["name"][$i];
$tmp_name=$_FILES["photo_url"]["tmp_name"][$i];
move_uploaded_file($tmp_name, "$structure/$name");
$images[] = "$structure/$name";
}
}
$all_images = implode(",",$images);
?>
</body>
</html>
$sql = "INSERT INTO image_details(tour_id,photo_url) VALUES('".$id."','".$all_images."')";
mysql_query($sql);
echo $sql;
试验
$sql=“插入图像详细信息(巡演id、照片url)值(“$id.”、“$all图像”。”);
mysql_查询($sql);
echo$sql;
正确的输出是什么?你要处理的输入是什么?我想一次上传两个或多个图像到数据库中,我一次要处理多个图像。据我所知,你只检查一个文件输入,而不是两个,或者文件名是一个数组,我们不知道,但我们猜测它可能是的重复。我只想将图像文件上传到数据库中