您好我正在尝试从我的 android 应用程序将图像文件上传到我的服务器。似乎我无法将任何文件上传到我的服务器而不是特定目录(图片)。如果我尝试上传到图片的子目录,那么 fopen 会返回 false。这是我的 php 文件
<?php
$base=$_REQUEST['image'];
$picname=$_REQUEST['picname'];
$binary=base64_decode($base);
header('Content-Type: bitmap; charset=utf-8');
//$shapicname = SHA1($picname);
$dir1 = 'pics/'.substr($picname,0,2);
$dir2 = substr($picname,2,2);
$targetfilename1 = $dir1;
$targetfilename2 = $dir2;
if (!file_exists($dir1)) {
mkdir($dir1); //create the directory
chmod($targetfilename1, 0777); //make it writable
}
//chdir($dir1);
$file = fopen('/var/www/html/'.$dir1.'/'.$picname, 'wb');
if (!$file) {
echo "false ".$dir1.$picname;
}
else {
$fwrite = fwrite($file,$binary);
fclose($file);
echo "uploaded".$fwrite.$file;
}
?>
pics 文件夹归 apache 用户所有,拥有 0777 权限
有任何想法吗?
我正在发布 php 错误日志
[2012 年 8 月 2 日星期四 18:32:34] [错误] [客户端 xx.xx.Xxx.xx] PHP 警告:fopen():安全模式限制生效。uid/gid 为 0/0 的脚本不允许访问第 23 行的 /var/www/html/uploadshaimage.php 中的 uid/gid 48/48 拥有的 /var/www/html/pics/53 [Thu Aug 2012 年 2 月 18 日 32 分 34 秒] [错误] [客户端 xx.xx.Xxx.xx] PHP 警告:fopen(/var/www/html/pics/53/5344.jpg):无法打开流:没有这样的文件或第 23 行 /var/www/html/uploadshaimage.php 中的目录