permissions?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sanderson
Forum Newbie
Posts: 2
Joined: Wed Nov 05, 2008 4:34 pm

permissions?

Post by sanderson »

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
<?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

}



?>
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: permissions?

Post by JAB Creations »

Did you CHMOD the directory?
sanderson
Forum Newbie
Posts: 2
Joined: Wed Nov 05, 2008 4:34 pm

Re: permissions?

Post by sanderson »

yeah...
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Re: permissions?

Post by infolock »

if you are on linux, the answer is it's how you are defining the directory...

Code: Select all

 
 
$file_directory = "/files/"; //the directory you want to store the new file in
 
 
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.
Post Reply