473,830 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($fi lename)) {
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($f ilename)) {

print "File $filename is writeable<br>";

if (!$handle = fopen("$filenam e", 'a')) {
print "Cannot open file ($filename) for append";
exit;
}

// Write $somecontent to our opened file.
if (!fwrite($handl e, $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 4600
Brian Richmond wrote:
<?php (snip) if ($handle = fopen($filename ,'r')) {
print "File $filename is readable.<br>";
}

if (is_writable($f ilename)) {

print "File $filename is writeable<br>";

if (!$handle = fopen("$filenam e", '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\T EMP\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:1 941) 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
1873
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 image-upload, where the images are subsequently viewably by the general public. Currently I've created a dedicated "pictures" directory which world-writable into which the PHP script puts the form-uploaded images. The admin logging in is done via a...
2
3934
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 them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
13
4332
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 that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
4
4489
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 one of my webform pages which includes a button that pops up a window where you can upload files, if you upload files in this popup window, it seems to somehow clear out all of the session variables and the users get logged out. However, if...
2
1596
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"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /><br /> <input type="submit" name="submit" value="Submit" />
30
1986
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 the "editors" using PHP, cookies, etc. The question is what file permissions I need to allow for the content to be writable by my PHP script. Do I really need to give write permissions to the "other" group. Are all wikis really that vulnerable?...
6
2717
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) $progressUploadingPhotos=false; $error=chmod($add,0777); if (!$error) $progressUploadingPhotos=false;
1
1599
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 problem. Thanks in Advance Dev Code for HTML Page
65
5111
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 got errors of Failed to open file ./outdir/mytestout.txt. Below is the code: #include <stdio.h>
0
9786
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9641
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10769
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10479
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10523
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10199
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7741
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3073
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.