2012-10-14 8 views
0

작은 문제가 있습니다. 첨부 파일 이름이 php.but 인 첨부 파일이있는 이메일의 스크린 샷을 업로드했습니다. 디렉토리 이름이 "upload./"이므로 해당 부분을 제거하고 싶습니다. 내가 어떻게 할 수 있니?첨부 파일 이름에서 디렉토리 이름을 제거하는 방법

감사합니다. enter image description here

$message = $mes; 
       echo $message; 

       //echo $message; 
       $subject = $coursetitle; 
       $headers .= 'Cc: [email protected]' . "\r\n"; 

       ini_set("SMTP", "mail.amdt.lk"); 
       ini_set("sendmail_from", "[email protected]"); 

       // boundary 
       $semi_rand = md5(time()); 
       $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 

       // headers for attachment 
       $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 

       // multipart boundary 
       $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; 
       $message .= "--{$mime_boundary}\n"; 

       // preparing attachments 




         for($x=0;$x<count($files);$x++){ 
          $file = fopen($dir.$files[$x],"rb"); 
          $data = fread($file,filesize($dir.$files[$x])); 
          fclose($file); 
          $data = chunk_split(base64_encode($data)); 
          $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$dir.$files[$x]\"\n" . 
          "Content-Disposition: attachment;\n" . " filename=\"$dir.$files[$x]\"\n" . 
          "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; 
          $message .= "--{$mime_boundary}\n"; 
         } 



       // send 
       //echo $message; 
       $ok = mail($to, $subject, $message, $headers); 
       if ($ok) { 
       echo "<p>mail sent to $to!</p>"; 
       } else { 
       echo "<p>mail could not be sent!</p>"; 
       } 
+1

소스 코드없이 게시하여 질문을 해결할 수 없습니다. 구체적이어야합니다. 이 게시물을 닫을 수 있습니다. 문자열에 있기 때문에 점 (.)이 나타납니다. " 또는 '아래' –

+0

죄송합니다. 내 코드 – Yasitha

답변

2

당신은 스스로를하고있는 ... 파일 이름으로이기

"Content-Disposition: attachment;\n" . " filename=\"$dir.$files[$x]\"\n" 
                ^^^^ 

그것은 클라이언트 브라우저에 나타나야합니다 ... 파일이 서버에있는 위치와 관련이 없거나 서버에있는 이름과 관련이 없습니다. 이는 원격 사용자의 정보를위한 것입니다.

더 큰 계획에서 ... 자신의 MIME 메시지를 만들거나 mail()을 사용하지 마십시오. Mime은 PHPMailer와 Swiftmailer와 같은 훌륭한 라이브러리가 훨씬 적은 코드로 당신을 위해 그 일을 완벽하게 수행 할 때 고통 스럽습니다.

+0

을 게시 할 예정입니다. 답변의 두 번째 부분에 대해 두 번 upvote 할 것입니다! –

+0

네, 동의합니다 Mr.eicto 대단히 감사합니다. Marc B – Yasitha

0
$string = str_replace("upload./", "", $string); 

그게 모든 :)

2

사용 basename() 기능 :

$file="upload./file.jpg"; 
$basename=basename($file); 
$dirname=dirname($file); 
관련 문제