0
클라이언트 PC에서 파일 (.txt 또는 기타)을 가져 와서 서버에있는 어떤 디렉토리에 업로드 할 수 있는지 알아야합니다. 이 파일을 첨부 파일로 사용하여 전자 메일을 보내십시오 (그러나 더 이상 문제가되지 않습니다). 이것은 PHP 함수에 의해 수행되어야합니다. 아무도 도와 줄 수 없니?PHP - 클라이언트에서 서버로 파일 업로드
클라이언트 PC에서 파일 (.txt 또는 기타)을 가져 와서 서버에있는 어떤 디렉토리에 업로드 할 수 있는지 알아야합니다. 이 파일을 첨부 파일로 사용하여 전자 메일을 보내십시오 (그러나 더 이상 문제가되지 않습니다). 이것은 PHP 함수에 의해 수행되어야합니다. 아무도 도와 줄 수 없니?PHP - 클라이언트에서 서버로 파일 업로드
양식 내용 :
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form action="sendEmail.php" method="post" name="mainform" enctype="multipart/form-data">
<table width="500" border="0" cellpadding="5" cellspacing="5">
<tr>
<th>To Email</th>
<td><input name="toEmail" type="text"></td>
</tr>
<tr>
<th>Subject</th>
<td><input name="fieldSubject" type="text" id="fieldSubject"></td>
</tr>
<tr>
<th>Attach Your File</th>
<td><input name="attachment" type="file"></td>
</tr>
<tr>
<td colspan="2" style="text-align:center;"><input type="submit" name="Submit" value="Send File"></td>
</tr>
</table>
</form>
</body>
</html>
스크립트 처리하기 :
<?php
$to = $_POST['toEmail'];
$subject = $_POST['fieldSubject'];
// Get file info
$tmpName = $_FILES['attachment']['tmp_name'];
$fileType = $_FILES['attachment']['type'];
$fileName = $_FILES['attachment']['name'];
if (file($tmpName)) {
$file = fopen($tmpName,'rb');
$data = fread($file,filesize($tmpName));
fclose($file);
$randomVal = md5(time());
$mimeBoundary = "==Multipart_Boundary_x{$randomVal}x";
$headers = "From: $fromName";
$headers .= "\nMIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/mixed;\n" ;
$headers .= " boundary=\"{$mimeBoundary}\"";
$message = "This is test email\n\n";
$data = base64_encode($data);
}
$result = mail ("$to", "$subject", "$message", "$headers");
if($result){
echo "A email has been sent to: $to";
}
else{
echo "Error while sending email";
}
https://www.google.com/search?q=how+to+upload+files+using+php – EternalHour