【发布时间】:2016-06-04 10:35:05
【问题描述】:
我正在尝试遍历从表单发布的“$_FILES”类型的变量数组并处理每个图像并存储目录
代码是
if(isset($_POST['travsubli'])){
$date=Date('Y-m-d');
$uname=substr($utravlastname,0,5).substr($utravphone,5,10);
$destin=str_replace(array(" ","/","."),"-",$_POST['Destination']);
if(!is_dir("images/userimages/travelphotos")) {mkdir("images/userimages/travelphotos");}
if(!is_dir("images/userimages/travelphotos/$uname")){mkdir("images/userimages/travelphotos/$uname");}
echo "Check : ".$_FILES['TourPhoto1']['name']."<br>";
$photosarray=array($_FILES['TourPhoto1']['name'],$_FILES['TourPhoto2']['name'],$_FILES['TourPhoto3']['name'],$_FILES['TourPhoto4']['name'],$_FILES['TourPhoto5']['name'],$_FILES['TourPhoto6']['name']);
$pai=1;
foreach($photosarray as $pha){
$ext=pathinfo($pha,PATHINFO_EXTENSION);
if(!empty($ext)){
$newphotoname="Travelogue-Photo-$destin-$pai.$ext";
$newphotopath="images/userimages/travelphotos/$uname/$newphotoname";
if(move_uploaded_file($pha,$newphotopath)){
echo "Photo Successfully Uploaded !<br>";
}else{echo "Something went wrong with Photo Upload !<br>"; $e=error_get_last();echo $e['message']."<br>";}
}
$TourPhoto="TourPhoto$pai";
$$TourPhoto=$newphotoname;
echo $pha."->$TourPhoto->".$$TourPhoto.$pai."<br>";
$pai++;
}
我的问题,或者更确切地说,problem 是,
Move_uploaded_file 不起作用。
我认为这是因为我在 move_uploaded_file 命令中使用了 $_FILES['variable']['name'] 而不是 $_FILES['variable']['tmp_name']。
我的诊断正确吗?如果是这样,应该怎么做?因为,我已将数组中的“名称”参数分配给循环。如何将其撤消为循环内的“tmp_name”?或者还有其他更好的选择吗?
【问题讨论】:
-
为什么你不能只使用
tmp_name? -
@u_mulder 如果我使用 tmp_name,我无法获得文件的实际扩展名。它给了 .tmp
-
然后合并两个字段。
标签: php file-upload