<?php
if(isset($_POST['submit'])) //has the form been submitted?
{
$file_directory = "/files/"; //the directory you want to store the new file in
$file_name = strip_tags($_POST['file_name']);//the file's name, stripped of any dangerous tags
$file_ext = strip_tags($_POST['file_ext']); //the file's extension, stripped of any dangerous tags
$file = $file_directory.$file_name.$file_ext; //this is the entire filename
$create_file = fopen($file, "w+"); //create the new file
if(!$create_file)
{
die("There was an error creating/opening the file! Make sure you have the correct permissions!\n");
}
$chmod = chmod($file, 0755); //set the appropriate permissions.
//attempt to set the permissions
if(!$chmod)
{
echo("There was an error changing the permissions of the new file!\n"); //error changing the file's permissions
}
//attempt to write basic content to the file
if (fwrite($create_file, "Content goes here!") === FALSE) {
echo "Error writing to file: ($file)\n";
}
fclose($create_file);
echo "File was created successfully!\n"; //tell the user that the file has been created successfully
exit; //exit the script
}else{ //the form hasn't been submitted!
header("Location: addfile.html"); //redirect the user back to the add file page
exit; //exit the script
}
?>
permissions?
Moderator: General Moderators
permissions?
Ok this is probably a simple solution but im using this script to add a page to my site (found it online somewhere) but i always get the "There was an error creating/opening the file! Make sure you have the correct permissions!" error i have tried setting CHMOD to 777, i think the solution will be really obvious and i will kick my self lol
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: permissions?
Did you CHMOD the directory?
Re: permissions?
if you are on linux, the answer is it's how you are defining the directory...
this is telling both PHP and linux to look in / directory (which is the root directory, outside of htdocs, and this directory probably does not live here).
Your pathing is wrong. echo out getcwd() and see where you are. if it's correct, use ./ (dot slash) instead of /
If it's not correct, then define the full path to where you want to be.
Code: Select all
$file_directory = "/files/"; //the directory you want to store the new file in
Your pathing is wrong. echo out getcwd() and see where you are. if it's correct, use ./ (dot slash) instead of /
If it's not correct, then define the full path to where you want to be.