PHP编写的二进制文件

问题描述:

我已经写了一个PHP文件,该文件会保存在服务器和部分代码的JPEG文件被列为如下:PHP编写的二进制文件

//create folder if folder not exist 
if (!is_dir($save_path)){ 

    $old = umask(0); 
    $flag = @mkdir($save_path,0777); 
    umask($old); 

if(isset($flag)){ 
    $string = 'Folder Create Success!'."\n"; 
}else{ 
    $string= 'Folder Create Fail!'."\n"; 
} 
echo $string; 

}else{ 

    echo "Folder exist!!!!"; 

} 


//write the content to the server 
$base=$_REQUEST['image']; 
$binary=base64_decode($base); 
header('Content-Type: image/jpg; charset=utf-8'); 

if(!$file = fopen($path, 'wb')){ 

    echo 'Image upload Fail!'."\n"; 
    return; 
} 
else 
{ 

    fwrite($file, $binary); 
    fclose($file); 

} 

问题是,当我运行的代码,如果文件夹不存在,它仅创建文件夹,但内容无法保存在文件夹中。错误信息是:

[Thu Jul 05 16:59:06 2012] [error] [client 10.95.61.220] PHP Warning:fopen(/ mnt/csis/upload/newphoto/others/12346_test/12346_test_2012-07 -05_others_abc.jpg):未能打开流:权限被拒绝在/var/www/html/upload_image.php在线57

但是,如果我再次运行代码,由于该文件夹是在过去创建的,好好工作。内容可以保存在文件夹中......

任何我错了?我试图在网上找到答案,但仍无法解决问题。

任何人都可以帮助,非常感谢!

我会尝试改变文件夹的创建使用recursive flag

$flag = @mkdir($save_path . "/" . $file,0777,true); 
+0

遗憾地告诉你,结局都是一样的...... – user1411475 2012-07-05 09:38:40

+0

你确定吗?我看到你同时拥有'$ path'和'$ basepath' - 你可以'回显'它们并显示我吗? – alfasin 2012-07-05 09:41:05

+0

如果它仍然不起作用,请在打开文件之前尝试使用'chdir($ path);'。 – alfasin 2012-07-05 09:47:28