[英]Can you do move_uploaded_file by $_FILES['name'] instead of $_FILES['tmp_name'] in php
我试图遍历从表单发布的类型为'$ _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++;
}
我的问题甚至是问题是
Move_uploaded_file不起作用。
我想这是因为我在move_uploaded_file命令中使用的是$ _FILES ['variable'] ['name']而不是$ _FILES ['variable'] ['tmp_name']。
我的诊断正确吗? 如果可以,该怎么办? 因为,我已经在数组中分配了“名称”参数进行循环。 如何在循环内将其撤消到“ tmp_name”? 还是有其他更好的选择?
我不知道真正的问题是什么,但是您可以尝试以下操作:
$photosarray = array(
array(
'tmp_name' => $_FILES['TourPhoto1']['tmp_name'],
'real_name' => $_FILES['TourPhoto1']['name'],
),
array(
'tmp_name' => $_FILES['TourPhoto2']['tmp_name'],
'real_name' => $_FILES['TourPhoto2']['name'],
),
array(
'tmp_name' => $_FILES['TourPhoto3']['tmp_name'],
'real_name' => $_FILES['TourPhoto3']['name'],
),
// etc
);
foreach ($photosarray as $pha) {
$ext = pathinfo($pha['real_name'],PATHINFO_EXTENSION);
$path = '';
// make your path here
// copy file
move_uploaded_file($pha['tmp_name'], $new_path);
// do other stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.