<?php
 
$name = $_REQUEST['name'];
$path = $_REQUEST['path'];
$string = $_REQUEST['string'];
 
if (substr($path, -1, 1) !== '/')
	$path .= '/';
 
function error($error = '')
{
	die("ok=0&error=" . ($error));
}
 
$loc = explode('/', $path);
$iter = 0;
 
$dir = $path;
while(!file_exists($path))
{
	$dir = '';
	for ($i = 0; $i <= $iter; $i++)
	{
		if ($loc[$i] !== '/' && !empty($loc[$i]))
		{
			$dir .= $loc[$i] . '/';
		}
	}
 
	if (!file_exists($dir))
	{
		if ($dir === '/' || $dir === '//' || !@mkdir($dir))
		{
			error('Could not create path: ' . $dir);
		}
	}
 
	$iter++;
	if ($iter > count($loc) && !file_exists($path))
	{
		error('Could not create path');
	}
}
 
$fp = @fopen($path . $name, 'w');
if (!$fp)
	error('Could not open file for writing');
 
@fputs($fp, $string);
@fclose($fp);
 
die('ok=1');
 
?>