您好我有以下代码上传/插入图片,它工作正常。但是,如果图像名称中包含数字,则不会上传/插入图像,例如:IMG-20161225.png
但是当我上传/插入图片名称例如:image.png 时,会上传。我的代码有什么需要改变的吗?谢谢!
ini_set('upload_max_filesize', '10M');
$date = date('y/m/d H:i:s');
function insertFile($filename,$date,$id){
$sql = mysql_query("INSERT INTO upload (up_id, up_name,up_date,app_id) VALUES (NULL,'$filename','$date',last_insert_id())");
if($sql){
return true;
}else{
return false;
}
}
if(!isset($_FILES['filename'])){
echo "";
}
else{
$error=array();
$extension=array("jpeg","jpg", "png");
foreach($_FILES["filename"]["tmp_name"] as $key=>$tmp_name)
{
echo $file_name=$_FILES["filename"]["name"][$key];
echo $file_tmp=$_FILES["filename"]["tmp_name"][$key];
echo $size=$_FILES["filename"]["size"][$key];
$ext=pathinfo($file_name, PATHINFO_EXTENSION);
if(in_array($ext,$extension))
{
if(!file_exists("../upload/".$file_name)){
if(move_uploaded_file($file_tmp=$_FILES["filename"]["tmp_name"][$key], "../upload/".$file_name)){
//echo "Success on File Not Exist";
$insert = insertFile($file_name,$date,$id);
}
else{
echo mysql_error();
}
}
else
{
$filename=basename($file_name,$ext);
$newFileName=$filename.time().".".$ext;
if(move_uploaded_file($file_tmp=$_FILES["filename"]["tmp_name"][$key], "../upload/".$newFileName)){
$insert = insertFile($newFileName,$date,$id);
}
}
}
}