Php 迅捷邮递公司';错误异常';带有消息';fopen(/tmp/…)无法打开流:权限被拒绝';
我已经在Php 迅捷邮递公司';错误异常';带有消息';fopen(/tmp/…)无法打开流:权限被拒绝';,php,laravel,shared-hosting,swiftmailer,Php,Laravel,Shared Hosting,Swiftmailer,我已经在cpanel共享主机上部署了laravel应用程序 当使用ignMailclass发送电子邮件时,以下错误会随机发生。(有时会发送邮件,但有时会发生错误) 我联系了主机支持人员,他们说我需要更改默认的临时目录 在SwiftMailer软件包lib/preferences.php中,名为$tmp的变量设置为getenv('TMPDIR'),文件中的注释说明: // You can override the default temporary directory by setting the
cpanel
共享主机上部署了laravel
应用程序
当使用ignMail
class发送电子邮件时,以下错误会随机发生。(有时会发送邮件,但有时会发生错误)
我联系了主机支持人员,他们说我需要更改默认的临时目录
在SwiftMailer软件包lib/preferences.php
中,名为$tmp
的变量设置为getenv('TMPDIR')
,文件中的注释说明:
// You can override the default temporary directory by setting the TMPDIR environment variable.
我试图以不同的方式设置TMPDIR
1) .htaccess:SetEnv TMPDIR/home/../laravel4/app/storage/my_temp
2) 在app/start/global.php
和app::before
回调函数中使用php putenv
函数
3) 在使用php putenv
函数设置$temp的行之前的lib/preferences.php
但其中没有一个更改打开的文件的路径,并导致无法打开流:权限被拒绝错误
以下是swiftmailer/lib/preferences.php
<?php
/****************************************************************************/
/* */
/* YOU MAY WISH TO MODIFY OR REMOVE THE FOLLOWING LINES WHICH SET DEFAULTS */
/* */
/****************************************************************************/
$preferences = Swift_Preferences::getInstance();
// Sets the default charset so that setCharset() is not needed elsewhere
$preferences->setCharset('utf-8');
// Without these lines the default caching mechanism is "array" but this uses a lot of memory.
// If possible, use a disk cache to enable attaching large attachments etc.
// You can override the default temporary directory by setting the TMPDIR environment variable.
// The @ operator in front of is_writable calls is to avoid PHP warnings
// when using open_basedir
$tmp = getenv('TMPDIR');
if ($tmp && @is_writable($tmp)) {
$preferences
->setTempDir($tmp)
->setCacheType('disk');
} elseif (function_exists('sys_get_temp_dir') && @is_writable(sys_get_temp_dir())) {
$preferences
->setTempDir(sys_get_temp_dir())
->setCacheType('disk');
}
// this should only be done when Swiftmailer won't use the native QP content encoder
// see mime_deps.php
if (version_compare(phpversion(), '5.4.7', '<')) {
$preferences->setQPDotEscape(false);
}
您需要检查试图写入目录的进程是否可以写入目录。您可以通过执行以下命令来验证流程使用的用户和组:
<?php
echo getmyuid().':'.getmygid();
?>
托管提供商是否告诉您需要将临时目录更改到哪个目录?@lowerends否,但新临时目录的权限为755您可以调试当前设置的TMPDIR
?您可以使用dd($\u ENV['TMPDIR'])
。@lowerends就在$tmep赋值之前,它是我设置的值问题是是可写的
返回false
,目录权限是0755,即使我将其设置为0777可写
仍然返回false
,并导致执行elseif
块
<?php
echo getmyuid().':'.getmygid();
?>
chown -R user:group writable_directory/