0

電子メールからサーバーに添付ファイルを保存しようとすると、これまでのところスクリプトは正常に動作しますが、wp ルート フォルダーにファイルが保存されます。

foreach ($attachments as $key => $attachment) {
    $name = $attachment['name'];
    $contents = $attachment['attachment'];
    file_put_contents($name, $contents);
}

ファイルを別のフォルダに保存するにはどうすればよいですか?

このコードを試してみましたが、うまくいきませんでした。

foreach ($attachments as $key => $attachment) {
    $name = $attachment['name'];
    $contents = $attachment['attachment'];
    file_put_contents(get_stylesheet_directory_uri() . '/email_attachments/' . $name, $contents);
}

何か案が?

4

3 に答える 3

0

今後の参考のために、パスを見つける方法は次のとおりです。

foreach ($attachments as $key => $attachment) {
        $name = $attachment['name'];
        $contents = $attachment['attachment'];
        file_put_contents(STYLESHEETPATH . '/email_attachments/' . $name, $contents);
    }
于 2015-05-27T17:35:51.893 に答える
0

パスを正しく追加しています。それは、get_stylesheet_directory_uri() が Web パス用であることだけです: https://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri

get_home_path() のようなものを試してください: https://codex.wordpress.org/Function_Reference/get_home_path

乾杯!

于 2015-05-27T17:00:15.223 に答える