我想在上传图片时根据当前日期按年月日来放图片,于是就有了如下代码
以上代码在本地测试环境(PHP+apache+MySQL)测试通过没有问题。但当我上传代码到服务器的时候会报如下错误
Warning: mkdir() [function.mkdir]: open_basedir restriction in effect. File(D:\hosting) is not within the allowed path(s): (D:\hosting\wwwroot\;D:\hosting\System\;C:\WINDOWS\Temp\) in D:\hosting\wwwroot\obbzz_com\htdocs\mytest.php on line 47
请问这种情况一般是由什么原因导致的?
回复内容:
我想在上传图片时根据当前日期按年月日来放图片,于是就有了如下代码
以上代码在本地测试环境(PHP+apache+MySQL)测试通过没有问题。但当我上传代码到服务器的时候会报如下错误
Warning: mkdir() [function.mkdir]: open_basedir restriction in effect. File(D:\hosting) is not within the allowed path(s): (D:\hosting\wwwroot\;D:\hosting\System\;C:\WINDOWS\Temp\) in D:\hosting\wwwroot\obbzz_com\htdocs\mytest.php on line 47
请问这种情况一般是由什么原因导致的?
你生成多级目录的地方有问题,php不可能一次生成多级目录date("Y/m/d"),你必须循环检测目录是否存在,如果不存在然后再一级一级的创建
看来明显是没有翻阅过 PHP 官方文档
http://php.net/manual/en/function.mkd...bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )
第三个参数为 true 就可以了,类似于 Java 的 File.mkdirs
下面这个是我使用的函数,挺好用的。function mkdirs($dir)
{
if(!is_dir($dir))
{
if(!mkdirs(dirname($dir))){
return false;
}
if(!mkdir($dir,0777)){
return false;
}
chmod($dir, 0777);
}
return true;
}
本文原创发布php中文网,转载请注明出处,感谢您的尊重!