2016-09-08 3 views
0

동일한 이미지를 두 개의 다른 디렉토리에 업로드하려고하지만 upload/이라는 첫 번째 디렉토리에만 업로드합니다. 복사 명령을 시도했지만 photo/이라는 두 번째 디렉토리에 파일을 업로드 할 수 없습니다. 어떻게해야합니까?동일한 이미지를 두 개의 다른 디렉토리에 업로드

<?php 

$uname=strip_tags($_POST['uname']); 

//$uname='user1'; 
$session_uid='user1'; 

$path='upload/'; 
$path1='photo/'; 


include_once 'background.php'; 

$valid_formats = array("jpg", "png", "gif", "bmp","jpeg","PNG","JPG","JPEG","GIF","BMP"); 
if(isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST" && isset($session_uid)) 
{ 
$name = $_FILES['photoimg']['name']; 
$size = $_FILES['photoimg']['size']; 


if(strlen($name)) 
{ 
$ext = getExtension($name); 
if(in_array($ext,$valid_formats)) 
{ 
if($size<(1024*1024)) 
{ 

$actual_image_name = time().$session_uid.".".$ext; 
$tmp = $_FILES['photoimg']['tmp_name']; 
$bgSave='<div id="uX'.$session_uid.'" class="bgSave wallbutton blackButton">Image Saved</div>'; 
if(move_uploaded_file($tmp, $path.$actual_image_name)){ 

echo $bgSave.'<img src="http://localhost/testing/'.$path.$actual_image_name.'" id="timelineBGload" class="headerimage ui-corner-all" style="top:0px"/>'; 

} 

// try upload to the second directyory 
if(!copy ($path, $path1.$actual_image_name)){ 
throw new Exception('Could not move 2nd file'); 
exit(); 
} 


else 
{ 
echo "Fail upload folder with read access."; 
} 
} 
else 
echo "Image file size max 1 MB"; 
} 
else 
echo "Invalid file format."; 
} 

else 
echo "Please select image..!"; 

exit; 
} 
?> 

답변

0

마찬가지로 move_uploaded_file()에서와 마찬가지로 파일의 전체 경로를 제공해야합니다. $tmp = $_FILES['photoimg']['tmp_name']은 원본 임시 파일의 전체 경로입니다. 따라서 이동 후 $path$actual_image_name을 사용하여 전체 소스 경로를 제공해야합니다.

if(!copy($path.$actual_image_name, $path1.$actual_image_name)){ 
    throw new Exception('Could not move 2nd file'); 
    exit(); 
} 
관련 문제