<?php
$oldumask = umask(0);
mkdir($url, 0777);
umask($oldumask);

$myFile = $url."/index.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData ="lots of things";
?>

Why am I not being allowed to write files to my website, it was recently working, my host had some technical issues yesterday,, and now it isn;t working.... are they directly related or is this just coincidence?

If just a coincidence.. can anyone offer any solutions please?!

Dani AI

Generated

Useful troubleshooting checklist and a small test you can run when PHP stops creating or writing files.

As pointed out, permissions are a common reason, but other frequent causes include wrong paths, ownership mismatches (web server user vs file owner), PHP restrictions (open_basedir, disabled functions, chrooted/php-fpm pools), full disk or user quotas, and OS-level controls like SELinux/AppArmor. The thread shows code that creates directories and opens files, so verify each step rather than assuming the create/write call is the only place to look.

Practical, ordered checks

  • Turn on error reporting and check PHP and webserver error logs first; these often show the real reason.
  • Verify the exact filesystem path your script uses (use absolute paths or DIR). Relative paths can point somewhere unexpected.
  • Check writability with is_writable() on the target directory, and confirm owner/group with ls -l (or your control panel). Prefer fixing ownership (chown to the web user) over setting world-writable perms. Use 0755 for dirs and 0644 for files where possible; 0777 is a last resort and insecure.
  • Confirm PHP-level limits: open_basedir, disable_functions, suhosin/safe_mode (older installs), and any PHP-FPM chroot.
  • Check disk space and quotas (df -h and quota tools) and OS access controls (SELinux/AppArmor).

Quick writable-test you can drop into a script (writes to system temp dir and reports errors):

$tmp = sys_get_temp_dir();
$testFile = $tmp . DIRECTORY_SEPARATOR . 'php_write_test_' . uniqid() . '.txt';

if (file_put_contents($testFile, "ok", LOCK_EX) !== false) {
    @unlink($testFile); // cleanup
} else {
    $err = error_get_last();
    error_log('Write test failed: ' . ($err['message'] ?? 'unknown'));
}

Notes: avoid relying on global umask changes in shared hosting; if you suspect host-side maintenance or a policy change, ask the host for recent configuration changes and include error-log snippets and ownership/perm output when troubleshooting.

Recommended Answers

All 2 Replies

I don't know if this may help but could be the file or folder your trying to write has only read permission try changing it inside your file mrg in c-panel or which ever hostpanel your using.

I don't know if this may help but could be the file or folder your trying to write has only read permission try changing it inside your file mrg in c-panel or which ever hostpanel your using.

Cheers for the response it was actually a coding error prior to this bit of code... i have corrected teh error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.