Jump to content

Recommended Posts

Hello, I have an issue on a script that works beautifully except for when I am wanting to save to a file. I have a domain setup in cPanel where the web files are in the normal public_html folder. Then I have setup a subdir (../edit) with a script that allows editing of .HTM files through the SPAW editor. I have setup a form to submit the changes to a variable and then I want to save the variables values to the selected file. Below is my code. What happens is that, even with file permissions at '0777', the file will not write and will not open. If permissions are set at '0776', the error returns that the file is not writable. I am thinking that this is an ownership issue and if so, is there any way around this? Do I have to implement a temporary file structure?

 

$fileDir = "../";
if ((isset($_POST['pageToEdit'])) && ($_POST['pageToEdit'] != NULL) && ($_POST['pageToEdit'] != '') && ($_POST['pageToEdit'] != ' ') && (isset($_POST['fileSelect'])) && ($_POST['fileSelect'] != NULL) && ($_POST['fileSelect'] != '') && ($_POST['fileSelect'] != ' ')) {

  $fileToSave = $fileDir . $_POST['fileSelect'];
  echo "File to save set to '$fileToSave'. ";

  if (is_writable($fileToSave)) {

    $openFile = fopen($fileName, "w+");

    if ($openFile) { echo $fileToSave . ' has been opened. '; 
    } else { echo $fileToSave . ' was not able to be opened! '; }

    if (fwrite($fileToSave, $_POST['pageToEdit']) === FALSE) { echo "<p class=\"error\">Cannot write to file ($filename)</p>";
    } else { echo "<p class=\"noError\">Updates successfully written to $fileToSave!</p>"; }

  } else { echo "<p class=\"error\">$fileToSave is not wriable or does not exist.</p>";}

} else if (isset($_POST['pageToEdit'])) { echo "<p class=\"error\">Could not save the changes to $fileToSave!</p>"; }

Link to comment
https://forums.phpfreaks.com/topic/74476-using-fwrite-on-a-cpanel-server/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.