f



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

?>
0
webmaster
2/22/2004 7:28:05 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

2 Replies
9185 Views

Similar Articles

[PageSpeed] 3

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  =--
0
hexkid2 (1017)
2/22/2004 8:02:47 PM
Pedro Graca <hexkid@hotpop.com> wrote in message news:<c1b1t7$1g9eac$2@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.
0
webmaster
2/25/2004 2:10:01 PM
Reply:

Similar Artilces:

PHP File upload
Hi, I have to allow my visitors to upload image on my site. I am using the follwoing code to do that: $uploaddir = 'admin/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); My problem is that I expect them to use same file name, like all of them will be uploading files like, comments.rtf. So if there is already one comments.rtf the file will get overwriten... so the challenge is to rename the files to username-filename.rtf can anybody here will take the pain to modify...

PHP file upload unexpected error
Hi, I have a short basic script to upload files. It works fine with small files, but with longer files it gets stuck. Here's the fragment, the input file is loaded in "$file" from an HTML form as usual. .... $img_str = fread(fopen($file, "r"), filesize($file)); $data = addslashes($img_str); // --------------------- up to here the execution is correct and fast (<1 second) $sql="INSERT INTO $table (". " file_name,". " file_type,". " file_size,". " bin_data)". " VALUES (". " ...

Q: File Exchange --- posted file not there yet. Should I upload file again?
I posted a file to the file exchange yesterday, but it is not showing up yet. How long does it usuallly take for the file to show up? Should I upload it again or wait? James Tursa James Tursa <aclassyguywithaknotac@hotmail.com> wrote in message <f058j3h10e632t855riru5bocpodhvgu3k@4ax.com>... > > I posted a file to the file exchange yesterday, but it is not showing > up yet. How long does it usuallly take for the file to show up? Should > I upload it again or wait? > > James Tursa It can take a few days depending on workload, holidays/weekends, sick days etc....

file.exe file generation from file.m file
How to generate application (*.exe) file from *.m file, which has lots of graphics. Program was written for image watermarking by using image processing toolbox. I want to send this program some where else but with out sowing the program codes. By this *.exe no need to use matlab6.5 platform. Also tell me How to generate *.p file from *.m file Which is hide the code to user but for run this program need matlab6.5 Please give me some idea about it. it is very urgent for me. I will be very great full to you "Biswajit Kar" <hibiswajitkar@rediffmail.com> wrote in message ne...

upload file error 3: "The uploaded file was only partially uploaded"
I've a file that starts like this: <form id="pdsForm" method="post" action="/mcControlPanel.php" class="mcForm" charset="UTF-8" enctype="multipart/form-data" > and it contains this input: <input id="biopic" name="biopic" type="file" /> The script recieving it does this: $biopic = $this->core->getVar("biopic"); if (is_array($biopic)) { print_r($biopic); I get: Array ( [name] => L-monkeySmall.jpg [type] => [tmp_name] => [error] => 3 [size] =&g...

File Upload issue
I am using PHP Version 4.4.3 under Linux/Apachie to upload files. The PHP.ini upload_max_filesize is 2M, which I need to override this in the HTML (see below). I changed the MAX_FILE_SIZE to 4,000,000 but the system only accepts files less than 2M. Is the override wrong, do I need to raise the limit in the PHP.ini file, or is the Apachie issue. <form name="upload" action="admin.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="4000000"> On Wed, 29 Nov 200...

I can not get file uploads to show up when I upload a file
I've a form that starts off like this: <form method="post" action="profile.php? id=5&formName=my_story_edit.htm" enctype="multipart/form-data"> <p>Email address:<br /> <input type="text" name="totalFormInputs[users][5][email_address]" value="lawrence@krubner.com" /></p> <p>Zip code:<br /> <input type="text" name="totalFormInputs[users][5][zip_code]" value="22902" /></p> <p>Personal image:<br /> <input type="fi...

Create Files/ Upload Files
Hi Can anyone explain by example how to create a new file on server and then upload some files to that newly created folder? But before we create the file check that an existing file does not already exist and then upload the files to the newly created directory. Thanks Baka On Jun 26, 7:49 am, abhm <bak...@gmail.com> wrote: > Hi > > Can anyone explain by example how to create a new file on server and > then upload some files to that newly created folder? > > But before we create the file check that an existing file does not > already exist and then upload the f...

file upload not saving file
Hello, When I upload an image to the server I get the message: Warning: Only -1 bytes were written, expected to write 547 The server phpinfo lists : file_uploads On upload_max_filesize 2M upload_tmp_dir /tmp PHP Version 4.4.1 so I created a directory named tmp at the root of my "server space" and gave it chmod 777, but still the same error occurs. This is the result of print_r($_FILES['myfile']) : Array ( [name] => 2.jpg [type] => [tmp_name] => [error] => 7 [size] => 0 ) Error 7 in the PHP manual is : UPLOAD_ERR_CANT_WRITE Value: 7; Failed to wri...

PHP upload
Hi, I have to allow my visitors to upload image on my site. I am using the follwoing code to do that: $uploaddir = 'admin/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); My problem is that I expect them to use same file name, like all of them will be uploading files like, comments.rtf. So if there is already one comments.rtf the file will get overwriten... so the challenge is to rename the files to username-filename.rtf can anybody here will take the pain to modify...

I need to create html files from php files using php
I am very new to PHP, although I have been using ASP for a few years. I use a product in ASP called ASPTear, it's a small dll that my hosting company happens to have loaded. Basically you can set up a function that you can pass an ASP page to and it will read the ASP and write out an HTML file. I use this to save load on the server and speed up my site, I have a few include files that look up data and then present it, this data does not change very often, so I run a routine called rebuildhtml.asp that will call a few ASP files and create HTML versions. I am now converting the site to P...

file extention from file file location
Hi, I am new to perl (only working on this one problem) but I program in other languages. We have an upload script written in cgi. Can anyone tell me how to get the file extension from the variable $File1 (actual file location on uploader's computer) then find out if it is equal to "txt" Thanks in advance for not telling me to read the manual. Ron -- PLEASE NOTE: comp.infosystems.www.authoring.cgi is a SELF-MODERATED newsgroup. aa.net and boutell.com are NOT the originators of the articles and are NOT responsible for their content. HOW TO POST to co...

Open .php file with PHP Designer 2007 by clicking the file in XP
In windows XP, I want to be able to click on a .php file and have it opened in PHP Designer 2007, Or right-click on it and have an "edit" menu option presented to me. I know how to tweak the registry to do this in general, but what would the command line look like in this specific case ? PHP Designer does not do this automatically. It is as if the program does not allow commandline options. It only opens with the last file used or a menu of recently opened files. ...

want to get content of one php file in another php file
i have one php file having content Contents of ex1.php file <body> <?php $content = "c://webserver/www/abc.php"; $handle = fopen($content, "r"); echo fread($handle,filesize($content)); ?> </body> this is reading abc.php file in which i m simply using an echo statement. When i execute ex1.php file i cant see the php statement of abc.php file content of abc.php file is <?php echo "hello";?> sarika wrote: > i have one php file having content > > Contents of ex1.php file > <body> > <?php > $content = "c://web...

Is a PHP variable supposed to be seen in a .js file included into a .php file
Is a PHP variable supposed to be seen in a .js file included into a .php file? I have a client side javascript code stored in a .js file which is included into a PHP file using <script src="filename.js></script> This code initialises a Javascript variable var u="string"; The string is supposed to be the value of $HTTP_HOST So, when initialise this variable like var u=<? echo $HTTP_HOST;?>; I sterted getting a javascript message Syntax Error Am I doing something wrong, or PHP variables are not seen in included js files? aa wrote: > Is a PHP var...

Web resources about - File Upload - directory is writable, file is not - comp.lang.php

Wikipedia:Quick directory - Wikipedia, the free encyclopedia
This page is a handy directory to various locations of interest in Wikipedia. Only dynamic pages should be listed here, no policy pages etc. ...

Telephone directory - Wikipedia, the free encyclopedia
"Phone book" and "White pages" redirect here. For a contact list, see Contact list . For other uses, see White pages (disambiguation) . Subscriber ...

Business Directory Listings: Eight Smart Tips for You to Get Started
If you are considering a business directory listing for your small business, congratulations – you are on the right track. Local SEO, local customers, ...

Atlas Partner Directory Launched
... just for Facebook and Instagram –advertising platform Atlas has one, as well. On that note, Atlas Tuesday introduced the Atlas Partner Directory ...

Slack announces App Directory store
... create more apps for the store, and a new framework called Botkit which should simplify the process of creating apps. The Slack App Directory, ...

The British Library’s ‘Save Our Sounds’ Program Creates Directory of UK Sound Collections
The long-feared deterioration of the world's sound collections is a coming to a head with the British Library's last-ditch initiative called ...

Amazon brings Microsoft users into AWS with Active Directory service
Amazon has launched an AWS Directory Service for Active Directory , a fully managed implementation of Microsoft's authentication and user management ...

Hackers leak DHS staff directory, claim DOJ is next
On Sunday, an account on Twitter posted a Department of Homeland Security staff directory with 9,355 names. Shortly after the DHS data was posted, ...

'Twitch Plays' directory makes it easy to find new games
The huge success that is TwitchPlaysPokemon gave rise to a number of other Twitch Plays games, and the video platform wants to make sure you ...

Azure Active Directory Enables One-Step MDM in Windows 10
DAILY VIDEO: Microsoft enables one-step MDM in Windows 10; IRS breach more extensive than first reported; Georgia Tech finds 11 deep security ...

Resources last updated: 2/14/2016 3:06:24 AM