我有抓住的Joomla中的用户ID并创建一个具有ID的目录(如果它不存在尚未)这diretorio.php文件:PHP:保存文件到指定目录
/* Get the current user id */
$user = JFactory::getUser();
$usr_id = $user->get('id');
/*Define the path to this user's directory */
$diretorio=$_SERVER['DOCUMENT_ROOT']."/Apps/files/".$usr_id;
/*Create the user's directory if it doesn't exist */
if (!file_exists($diretorio) and !is_dir($diretorio)) {
mkdir($diretorio, 0755);
};
现在,我想保存数据的文件中的对象,使用Ajax的触发另一个PHP文件上面创建的目录:
$myFile = $diretorio."/dados.json";
$fh = fopen($myFile, 'w') or die("não é possível abrir o ficheiro");
$stringData = $_POST['data'];
$stringData='{ "data":'.json_encode($stringData).'}';
fwrite($fh, $stringData);
fclose($fh);
但是,不创建的文件。如果我将第一行替换为:
$myFile = "dados.json";
它将在存储此PHP脚本的同一目录中创建文件。
我会电子书籍采取看看[的Joomla文件系统文件(HTTP:/ /docs.joomla.org/How_to_use_the_filesystem_package) – Lodder
您是否配置了PHP来显示/记录所有类型的错误消息?什么'fwrite()'返回? –
它不会返回任何错误。即使报告标准设置为最大值 –