사용자가 업로드 한 이미지를 'temp'라는 폴더에 업로드하고 업로드 위치를 $ _SESSION [ 'uploaded_photos'] 배열에 저장할 수있는 업로드 양식이 있습니다. 일단 사용자가 '다음 페이지'버튼을 누르면, 그 폴더 바로 앞에서 동적으로 생성 된 새 폴더로 파일을 옮기고 싶습니다.어떻게 PHP를 사용하여 파일을 다른 폴더로 옮길 수 있습니까?
if(isset($_POST['next_page'])) {
if (!is_dir('../images/uploads/listers/'.$_SESSION['loggedin_lister_id'])) {
mkdir('../images/uploads/listers/'.$_SESSION['loggedin_lister_id']);
}
foreach($_SESSION['uploaded_photos'] as $key => $value) {
$target_path = '../images/uploads/listers/'.$_SESSION['loggedin_lister_id'].'/';
$target_path = $target_path . basename($value);
if(move_uploaded_file($value, $target_path)) {
echo "The file ". basename($value). " has been uploaded<br />";
} else{
echo "There was an error uploading the file, please try again!";
}
} //end foreach
} //end if isset next_page
사용되고있는 $ 값의 예는 다음
../images/uploads/temp/IMG_0002.jpg
그리고 $의 target_path의 일례 사용되는 즉 :
../images/uploads/listers/186/IMG_0002.jpg
temp 폴더에있는 파일을 볼 수 있습니다.이 두 경로가 모두 나에게 잘 보이고 mkdir 기능이 실제로 잘 된 폴더를 만들 었는지 확인했습니다.
어떻게하면 php를 사용하여 파일을 다른 폴더로 옮길 수 있습니까?