473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

File Upload - directory is writable, file is not

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";
}

?>
Jul 17 '05 #1
2 4580
Brian Richmond wrote:
<?php (snip) 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;
} (snip) }

?>


Why are you fopen()ing $filename twice?

I think it probably doesn't matter, but I don't like it :)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Pedro Graca <he****@hotpop.com> wrote in message news:<c1*************@ID-203069.news.uni-berlin.de>...

Why are you fopen()ing $filename twice?

I think it probably doesn't matter, but I don't like it :)


Good call, however fixing it doesn't help. The actual script that I'm
using to do the file upload gives me the following error, which is
what I'm trying to troubleshoot:

Warning: copy(): open_basedir restriction in effect.
File(C:\WINNT\TEMP\php39.tmp) is not within the allowed path(s):
(c:\winnt\temp\;e:\webroot\www) in e:\webroot\www\siteadmin.php on
line 1941

Warning: Cannot modify header information - headers already sent by
(output started at e:\webroot\www\siteadmin.php:1941) in
e:\webroot\www\siteadmin.php on line 1964

I've had the site admin change their php.ini file for these values:

upload_tmp_dir = "e:/webroot/www"; (To maybe allow temp files to write
under the web server directory, didn't work)

open_basedir = "c:\winnt\temp\; e:\wwwroot\www" (Thinking this might
also allow php to write to the system temp directory, also didn't work
but does show in the above error that the temp file is not in this
allowed path, even though it seems like it is)

This is the actual problem I'm trying to troubleshoot. The original
script that I included was to help understand where the write issue
was coming into play, but I think it's either PHP or IIS causing it.
If you have any further insight, I'd love to hear it.
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mark Hanford | last post by:
The Why: I'm in the process of creating a Linux+Apache+PHP website with a public area and an admin area for configuration and updates. The What: One of the features of the admin area is...
2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
4
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use...
2
by: rfhurley | last post by:
* dumb newbie alert * Hi, it's me again. This time I'm learning to upload files. I'm using an HTML form file: <form method=post action="upload_file.php" enctype="multipart/form-data">...
30
by: Adam Baker | last post by:
Hello, I'm writing a site where a handful of people will be able to edit the content using PHP scripts (FCKeditor). The content is stored as individual files in a directory. I'd like to validate...
6
by: Milan Krejci | last post by:
while(list($key,$value) = each($_FILES)) { if(!empty($value)){ $filename = $value; $add = "upimg/$filename"; echo $_FILES; $error=copy($_FILES, $add); if (!$error)...
1
by: Dev | last post by:
Dear All, I want to upload a file with PHP script. For that i use code given below. with this code my operation success but there is no file on my Server/Website Anyone help me to solve this...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.