fopen无法创建文件 [英] fopen can't create file

查看:224
本文介绍了fopen无法创建文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究需要PHP制作文件和文件夹的东西.我正在使用fopen创建文件.但是,它似乎不起作用.当我编写代码时,我在Windows上使用WAMP,并且一切正常,但是当我将站点移至Ubuntu服务器时,该脚本根本不起作用.

I’m working on something which requires PHP to make files and folders. I'm using fopen to create the file. However, it doesn't seem to work. When I was writing the code, I was on windows with WAMP and everything was working but when I moved the site to Ubuntu server the script simply doesn't work.

这是我用于在文件和zip上创建的代码

This is the code I’m using for the creation on the file and the ziping

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的文件夹,该sessionid是一个随机数,并在该文件夹内创建2个文件并压缩它们.请注意,该文件夹已创建,但其中没有文件

What the script does is to create a folder with the sessionid which is a random number and inside that folder create the 2 files and zip them. Note the folder is created but not the files inside

推荐答案

您应尝试为目录设置适当的权限.

You should try setting proper permissions for directory.

mkdir($sessionid, 777);

错了,你应该写

mkdir($sessionid, 0777);

这篇关于fopen无法创建文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆