【发布时间】:2014-06-27 09:19:14
【问题描述】:
我正在做一些需要 PHP 来制作文件和文件夹的东西。我正在使用fopen 创建文件。但是,它似乎不起作用。当我编写代码时,我在带有 WAMP 的 Windows 上,一切正常,但是当我将站点移动到 Ubuntu 服务器时,脚本根本不起作用。
这是我用于创建文件和压缩的代码
mkdir($sessionid, 777);
// create the server.properties
$server_config = fopen("$sessionid/server.properties",'a');
$config = "test";
fwrite($server_config,$config);
fclose($server_config);
// create the run.sh/bat
$server_script = fopen("$sessionid/RUN.$platform", 'a');
fwrite($server_script,$script);
fclose($server_script);
// zip them all together
$zip = new ZipArchive();
$ow = 1;
$file= "$sessionid/RFSLABSserver.zip";
if($zip->open($file,$ow?ZIPARCHIVE::OVERWRITE:ZIPARCHIVE::CREATE)===TRUE)
{
// Add the files to the .zip file
$zip->addFile("/$sessionid/server.properties", "server.properties");
$zip->addFIle("/$sessionid/RUN.$platform", "Start.$platform");
// file source as file name
$zip->close();
}
脚本的作用是创建一个带有随机数 sessionid 的文件夹,并在该文件夹内创建 2 个文件并压缩它们。注意文件夹是创建的,而不是里面的文件
【问题讨论】:
-
你不应该为一个简单的 web 应用程序设置 777 权限。