PDA

View Full Version : PHP configuration - help



lambrite
05-08-2003, 09:24 PM
I am trying to run a simple script to allow users to upload files to a directory. However, to do this, I need to configure my installation of PHP to have a temporary directory set. I've got lots of instructions - all having to do with the php.ini file, which I cannot find :?

Can anyone help me out with this?

Thanks,
Sarah

WestHost - CSimiskey
05-09-2003, 11:34 AM
To use your own custom php.ini, first off you must have a php.ini to use. I found one here that you can download and use:
http://ajmitch.dhis.org/~ajmitch/php4/php4-4.1.2/php.ini-recommended
Rename this to php.ini and put it in your cgi-bin directory.

Now you need to make sure that the server recognizes that you are using that ini so you need to create a .htaccess file in your /www directory that looks something like this:


Action application/x-httpd-php /cgi-bin/php
Action application/x-httpd-php-source /cgi-bin/php

That should take care of your problem, and you can then modify the php.ini to fit your needs.

lambrite
05-10-2003, 11:42 AM
Thanks - that helped a lot. I have two other questions...

I've tried several scripts to do the file upload, and all of them fail - the return message is (depending on what the script is set up to print) is either that the file size is 0 or the file failed to copy. I feel fairly certain that I have set up my directory paths incorrectly - I am not sure if they should be what I would use on the web, or what the actual path is. This is both within the script and in the ini file.

In the ini file, I have:
upload_tmp_dir = /home/www/anonftp/temp

In the upload script, I have:
$tmp_upload_path = "\\home\\www\\anonftp\temp";
$new_file_name = "\\home\\www\\anonftp\\incoming\\".$newname;

I have tried other paths, too, all of which did not work.

All the directory permissions are correct, and the max file sizes, memory usage, etc. are all set to be quite large enough to handle uploads...

Also, when Westhost 2 comes out with virtual servers, will all this change?

Thanks,
Sarah

lonestarr
05-11-2003, 07:49 PM
Here is the official link incase you haven't already checked it out.
http://www.php.net/manual/en/features.file-upload.php

I don't know if it is important to you to use your own temp directory or not. I have written several file upload scripts on Westhost servers that work just fine. Here is a script I just wrote and tested on my Westhost account. Maybe try it as a alternative to messing with your own php.ini file:


<HTML>
<HEAD><TITLE>Upload File</TITLE></HEAD>
<BODY>

<BR><BR>

<?

$destination = $DOCUMENT_ROOT."/files/";

if(isset($submit)){
copy( $userfile, $destination.$userfile_name );

echo $userfile_name." has been successfully uploaded.";
} else {

echo '<FORM METHOD="post" ENCTYPE="multipart/form-data" ACTION="'.$PHP_SELF.'">

What file would you like to upload?<BR>
<INPUT TYPE="file" NAME="userfile"> && <INPUT TYPE="Submit" NAME="submit" VALUE="Submit">

</FORM>';

}

?>

<BR><BR>

</BODY>
</HTML>


Ofcourse you'll want to change the $destination variable to whatever directory you want your uploaded files to be copied to. It is important that your upload form have the ENCTYPE="multipart/form-data" in the form tag. Also it is important that both your script and the destination directory have the correct permissions set. Otherwise you will generate an error. I hope that helps.

Anonymous
05-14-2003, 03:03 AM
The experience that I have had with this problem is that it is related to using the server's /tmp directory for your temporary upload location. A much better alternative is to either set the upload_tmp_dir variable in your php.ini to a directory in your account or do as in the code above and specify the temp directory in your script. A 3rd option is to use the set() function to set the php.ini variable during runtime.

lambrite
05-16-2003, 08:12 PM
I did finally get it worked out! Thanks to everyone!

Sarah

SteveW
05-28-2003, 08:10 AM
To use your own custom php.ini, first off you must have a php.ini to use.
Now you need to make sure that the server recognizes that you are using that ini so you need to create a .htaccess file in your /www directory that looks something like this:


Action application/x-httpd-php /cgi-bin/php
Action application/x-httpd-php-source /cgi-bin/php

That should take care of your problem, and you can then modify the php.ini to fit your needs.

Is there a way to use a custom php.ini file for a subdirectory? I don't want to alter the settings for the main site, just one section and below (ie /home/www/rootdir/subdir) - if I use the suggested .htaccess above, it doesn't see my custom php.ini file, and if I create a /subdir/cgi-bin and put the customphp.ini file in it, then modify /subdir/.htaccess to read
'... /subdir/cgi-bin/php' I get the following:

The requested URL /subdir/cgi-bin/php/subdir/filename.php was not found on this server.

I hope that's clear enough... kinda brain dead from pouring over http://httpd.apache.org/docs-2.0/mod/core.html#options to find the answer.. unfortunately I'm a windows guy & not a *nix/apache guy :)

WestHost - CSimiskey
05-28-2003, 12:28 PM
Steve,

Yes you can use a custom ini for individual directories by creating the above specified .htaccess file in the particular subdirectory.

No, I don't believe you will be able to specify a PHP executable outside of the cgi-bin, although it may not preclude you from creating a seperate directory in the cgi-bin with its own php and php.ini files within it. Note that it could become rather space consuming should you try to do different php.ini's for more than a couple of directories.

Not as important to the matter at hand, but the apache docs you should be looking at need to be for version 1.3.x, not 2.0. There are plenty of differences so it helps to be on the right page.

Hopefully that will get you taken care of.

SteveW
05-28-2003, 10:10 PM
ahhh... it's all so clear after getting a few hours sleep :) thanks!

WestHost - CSimiskey
05-30-2003, 09:37 AM
Sleep is overrated, it's only good for clearing out your body of old caffeine in preparation of receiving new caffeine. Glad it all makes sense, let us know if you need any other help.

SteveW
05-30-2003, 10:27 AM
Sleep is overrated, it's only good for clearing out your body of old caffeine in preparation of receiving new caffeine. Glad it all makes sense, let us know if you need any other help.

For the most part I agree, However, having only been coding for a little over a year now, I'm still at that stage where I'll find myself whipped into a coding frenzy, ignoring my body's cry for sleep until I get to the point where I'll be staring at the code, knowing I just changed something but have no idea what I just did or what I'm looking at... lol.. that's when I'm afraid to roll over in the morning and look at what's on the screen :)

lonestarr
05-30-2003, 05:56 PM
I hear ya there!