2012-12-29 2 views
-2

업로드 된 파일의 이름을 str_replace function으로 어떻게 바꿀 수 있습니까? _으로 space을 삭제하고 싶습니다. 어떤 도움이 필요합니까? 내가 파일파일 업로드시 str_replace 함수

$file1 = 'order_'.$orderId.'_'.$rowsOrder['image_a']; 
$file2 = 'order_'.$orderId.'_'.$rowsOrder['image_b']; 
$file3 = 'order_'.$orderId.'_'.$rowsOrder['image_c']; 
$file4 = 'order_'.$orderId.'_'.$rowsOrder['image_d']; 
$path1 = 'http://www.yourdomain.com/'.$file1; 
$path2 = 'http://www.yourdomain.com/'.$file2; 
$path3 = 'http://www.yourdomain.com/'.$file3; 
$path4 = 'http://www.yourdomain.com/'.$file4; 

 <tr>"; 
       if($rowsOrder['image_a'] !=''){ 
       $message.="<td align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><a href='http://www.yourdomain.com/files/".$file1."' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>File1</a></td>";} 
       if($rowsOrder['image_b'] !=''){ 

       $message.= "<td align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><a href='http://www.yourdomain.com/files/".$file2."' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>File2</a> </td>";} 


      $message.= "</tr><tr>"; 


      if($rowsOrder['image_c'] !=''){ 
       $message.= "<td align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><a href='http://www.yourdomain.com/files/".$file3."' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>File3</a></td>";} 
       if($rowsOrder['image_d'] !=''){ 
       $message.= "<td align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;'><a href='http://www.yourdomain.com/files/".$file4."' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>File4</a> </td>";} 
       $message.= "</tr><tr> 
         <td colspan='2' align='left' style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000;font-weight: bolder;'><br><br>Thanks,<br><br> 
          <span style='font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; color:#000000; font-weight: normal;'><a href='http://www.yourdomain.com/' style='font-family:Times New Roman, Times, serif; font-size:12px; color: #000000; font-weight: normal;' title='http://www.yourdomain.com/'>yourdomain</a></span></td></tr> 

$order_image_a='order_'.$orderId.'_'.$filea; 
if(!empty($filea)) move_uploaded_file($_FILES['FILE1']['tmp_name'], "../files/$order_image_a"); 

$order_image_b='order_'.$orderId.'_'.$fileb; 
if(!empty($fileb)) move_uploaded_file($_FILES['FILE2']['tmp_name'], "../files/$order_image_b"); 

$order_image_c='order_'.$orderId.'_'.$filec; 
if(!empty($filec)) move_uploaded_file($_FILES['FILE3']['tmp_name'], "../files/$order_image_c"); 

$order_image_d='order_'.$orderId.'_'.$filed; 
if(!empty($filed)) move_uploaded_file($_FILES['FILE4']['tmp_name'], "../files/$order_image_d"); 

내가 이미지 나 이름에 간극을 가진 모든 파일을 업로드하고있는 경우를 업로드 할 CODE 이하로 사용하고, 그것은 _에서 함께 업로드해야 간격의 장소 (예 - you files.docyou_files.doc으로 업로드해야 함). 가능한가? 어떤`str_replace` 또는`strtr`의

+0

는 당신이 move_uploaded_file''에 대한 최종 파일 이름을 생성 할 때 그것이 할 수있는 권리 장소 물론 ... 수행하기위한 것입니다, 당신은 출력하고하지 않을 때 상기 파일명. – DCoder

+0

업로드 된 파일 코드로 내 질문을 편집하십시오. 이제 제대로 작동하도록 함수를 추가 할 위치를 제안하십시오. – user1859847

+0

나는'_a'에서'_d'에 이르는 복사 - 붙여 넣기 코드 복제에 대한 큰 팬이 아닙니다. 일반적으로 배열이 더 편리합니다. 당신이 올린 코드는'$ fileda '를 통해'$ fileda'가 값을 얻는 방법을 보여주지 않으므로 여러분의 질문에 대답하기가 조금 어렵습니다. – DCoder

답변

0
function convertSpecialChars($str) { 
    $str = str_replace(" ", "_", $str); 
    return $str; 
} 

$filea = $this->convertSpecialChars($filea); 

$order_image_a='order_'.$orderId.'_'.$filea; 
if(!empty($filea)) move_uploaded_file($_FILES['FILE1']['tmp_name'], "../files/$order_image_a");