我有一个包含5个文件上传输入的html表单
<form action="../scripts/php/insert_imagery.php" method="post" enctype="multipart/form-data" name="upload" id="upload">
<input type="file" name="upload[0]" id="1"> Upload image 1 </input>
<input type="file" name="upload[1]" id="2"> Upload image 2 </input>
<input type="file" name="upload[2]" id="3"> Upload image 3 </input>
<input type="file" name="upload[3]" id="4"> Upload image 4 </input>
<input type="file" name="upload[4]" id="5"> Upload image 5 </input>
</form>
将它们发送到insert_imagery.php
insert_imagery.php为要放入的图像创建文件目录路径
mkdir($_SERVER['DOCUMENT_ROOT']."/profiles/".$username_entry."/user_images", 0777, true);
这一直有效,直到我添加文件上传脚本。当我添加它时,文件崩溃。
以下是我上传的代码......
$user_id = $rows['id'];
$business_name = $rows['business_name'];
$username_entry = $username_check;
$hashPass = password_hash($password, PASSWORD_BCRYPT);
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
global $link;
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = mysqli_real_escape_string($link, $theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mkdir($_SERVER['DOCUMENT_ROOT']."/profiles/".$username_entry."/user_images", 0777, true);
$user_image_dir = "profiles";
$user_images = "user_images";
if (isset($_FILES['upload']) === true) {
$files = $_FILES['upload'];
for($x = 0; $x < count($files['name']); $x++) {
$name = $files['name'][$x];
$tmp_name = $files['tmp_name'][$x];
move_uploaded_file($tmp_name, "$user_image_dir/{$username_entry}/{$user_images}/{$name}");
//echo '<pre>', print_r($files['name'][0], true), '</pre>';
$image_upload1 = ($files['name'][0]);
$image_upload2 = ($files['name'][1]);
$image_upload3 = ($files['name'][2]);
$image_upload4 = ($files['name'][3]);
$image_upload5 = ($files['name'][4]);
}
$insert_upload1 = "$user_image_dir/$username_entry/$image_upload1";
$insert_upload2 = "$user_image_dir/$username_entry/$image_upload2";
$insert_upload3 = "$user_image_dir/$username_entry/$image_upload3";
$insert_upload4 = "$user_image_dir/$username_entry/$image_upload4";
$insert_upload5 = "$user_image_dir/$username_entry/$image_upload5";
关于为什么这不起作用的任何想法或建议......谢谢。