我正在尝试从POST上传的文件中删除空格,因为这会给我带来问题,但是我无法让它工作。我在这里测试了这个片段,用下划线替换空格,然后将结果插入数据库fiels,但它只返回单词'Array'。我已经尝试了许多不同的方法,没有运气,主要是得到一个空白字段。我希望有人能帮忙指出我哪里出错了。
谢谢!
`
$count = $_POST['img_counter'];
$rand = mt_rand(10000, 99999);
for ($i = 0; $i <= count($_FILES['fileToUpload']['name']); $i++) {
$path = './uploads/' . $rand;
$temp = $_FILES['fileToUpload']['name']; // assigns file name to variable
$newfilename = str_replace(' ', '_', $temp); // replaces blank space with underscore and saves as new variable
if (!is_dir($path)) {
mkdir($path, 0777, true);
chmod($path, 0777);
}
$extension = pathinfo($_FILES['fileToUpload']['name'][$i], PATHINFO_EXTENSION);
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'][$i], $path . '/' . count() . $i . $_FILES['fileToUpload']['name'][$i])) {
$iCreatedAt = time();
$iUpdatedAt = time();
$iTokenNumber = $rand;
$vImageName = $newfilename; // mysql field for image name
chmod($path . '/' . count() . $i . $_FILES['fileToUpload']['name'][$i], 0777);
$query = "insert into shop_images (iTokenNumber,vImageName,iUpdatedAt,iCreatedAt) values ('$iTokenNumber','" . $vImageName . "','$iCreatedAt','$iUpdatedAt')";
if (!mysqli_query($conn, $query)) {
// echo mysqli_error();
echo "Something went wrong!";
} else {
//echo "success";
}
} else {
echo $_FILES['fileToUpload'][$i]['error'];
}
}
`