I'm writing a script to upload images along with articles to a
directory on the server. I'm developing it offline on my WinXP and
Apache 1.3.x laptop and it's working great, but when I move the script
to the server, I get write errors when the file attempts to upload.
So I set up a test script (included below) to test the directory
structures all the way up to the file, and every directory appears to
be writable, yet I can't write to the test file. I keep seeing
suggestions to set the open_basedir directive in the php.ini file to
solve this, but it's hasn't worked yet. Can anyone suggest what I can
try to get the uploads working?
<?php
$filename = 'images/articles/test.txt';
$somecontent = "Add this to the file\n";
if (! file_exists($filename)) {
print "The file $filename does not exist.";
}
// Check path availability up to the file
if (! is_writable('e:/webroot/www/images/articles')) {
print "Directory e:/webroot/www/images/articles is not
writable<br>";
}
else {
print "Directory e:/webroot/www/images/articles is writable<br>";
}
if (! is_writable('e:/webroot/www/images')) {
print "Directory e:/webroot/www/images is not writable<br>";
}
else {
print "Directory e:/webroot/www/images is writable<br>";
}
if (! is_writable('e:/webroot/www')) {
print "Directory e:/webroot/www is not writable<br>";
}
else {
print "Directory e:/webroot/www is writable<br>";
}
if ($handle = fopen($filename,'r')) {
print "File $filename is readable.<br>";
}
if (is_writable($filename)) {
print "File $filename is writeable<br>";
if (!$handle = fopen("$filename", 'a')) {
print "Cannot open file ($filename) for append";
exit;
}
// Write $somecontent to our opened file.
if (!fwrite($handle, $somecontent)) {
print "Cannot write to file ($filename)";
exit;
}
print "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
print "The file $filename is not writable";
}
?>