我正在建立一个广告网站,允许用户为每个广告上传多张照片,我该如何让它工作?我是 php 新手
<?php echo $error_msg; ?>
<?php
include_once "connection.php";
if(isset($_FILES['files'])){
$errors= array();
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $key.$_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
$file_type=$_FILES['files']['type'][$key];
if($file_size > 2097152){
$errors[]='File size must be less than 2 MB';
}
$sql = mysql_query("INSERT INTO upload_data (`postid`,`file_name`,`file_size`,`file_type`) VALUES('$postid','$file_name','$file_size','$file_type')")or die (mysql_error());
$desired_dir="uploads";
if(empty($errors)==true){
if(is_dir($desired_dir)==false){
mkdir("$desired_dir", 0700);
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}else{
$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir);
}
mysql_query($sql);
}else{
print_r($errors);
}
}
if(empty($error)){
echo "Success";
}
}
?>