4

昨日質問してアドバイスをもらって使ってみましたが、どういうわけかうまくいきません。そのため、ユーザーが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
など。

ありがとうございました!

4

1 に答える 1

5

使用する:

$attachment = Swift_Attachment::fromPath($target_path);

これは、ファイルを一時的な場所から移動したためです。move_uploaded_file$_FILES['uploadedfile']['tmp_name']を使用してファイルを移動する前のパスを返します。これは、が迅速なメーラーコードの範囲内にあることを前提としています$target_path

于 2010-07-20T17:39:06.750 に答える