Reputation: 179
$new_file=$data['url']."_files";
if(!is_dir($new_file))
mkdir ($new_file);
echo $new_file=$new_file.'\class.ticket.php';
$ourFileHandle = fopen($new_file, 'w') or die("can't open file");
echo fwrite($ourFileHandle, $new_data) or die('cannot write');
fclose($ourFileHandle);
fwrite() returns 1473
this does not write new file in other directory but creates file '$newfile\class.ticket.php in the same directory.
Can anone explain how i can put file in new directory.
Thanks
Upvotes: 1
Views: 1228
Reputation: 21449
On what operating system is your server running? in linux, directory separator is a forward slash, so maybe that's causing a problem. use the predefined constant DIRECTORY_SEPARATOR
to return the correct separator for the OS.
Upvotes: 1
Reputation: 11700
Try this:
$data['url'] = 'foo';
$new_data = '<?php echo \'Hello World!\';';
$new_file=$data['url']."_files";
if(!is_dir($new_file))
mkdir ($new_file);
$new_file=$new_file.'/class.ticket.php';
$ourFileHandle = fopen($new_file, 'w') or die("can't open file");
fwrite($ourFileHandle, $new_data) or die('cannot write');
fclose($ourFileHandle);
Upvotes: 0