昨日質問してアドバイスをもらって使ってみましたが、どういうわけかうまくいきません。そのため、ユーザーがHTMLフォームからサーバーにアップロードしたファイルの名前を取得する必要があります。このファイルを、PHP/SwiftMailerによって送信される電子メールに添付する必要があります。これが私のコード、ファイルアップロード部分です:
//File upload
// Where the file is going to be placed
$target_path = "uploads/";
// Add the original filename to our target path.
//Result is "uploads/filename.extension"
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
//End of file upload
これはファイル添付部分です:
//Create the attachment
$attachment = Swift_Attachment::fromPath($_FILES['uploadedfile']['tmp_name']);
サーバーからファイルを取得しないのはなぜですか?エラーメッセージは次のとおりです。間違ったディレクトリでファイルを見つけようとしているようです。
警告:fopen(/tmp/phpHJdw0H)[function.fopen]:ストリームを開くことができませんでした:/home/myserver/mydomain.com/Hawaii/html/swift-mailer/lib/classes/Swift/ByteStreamにそのようなファイルまたはディレクトリはありません/fileByteStream.phpの131行目致命的なエラー:キャッチされない例外「Swift_IoException」とメッセージ「/home/myserver/mydomain.com/Hawaii/html/swift-mailer/libの[/tmp/phpHJdw0H]を読み取るためのファイルを開くことができません」 /classes/Swift/ByteStream/FileByteStream.php:133スタックトレース:#0
など。
ありがとうございました!