Need help moving file PHP/PERL

Status
Not open for further replies.

DewChugr

Photoshop God
Jun 26, 2006
1,977
66
0
48.655139,-119.644032
I'm having a problem with my upload script. it appears that my hosts safe mode is prohibiting me from moving my uploaded temporary file to a permanant file in a directory. This is the error I get.


Warning: move_uploaded_file(): SAFE MODE Restriction in effect. The script whose uid is 643 is not allowed to access /home/virtual/site139/fst/var/www/html/gpx-files/Al owned by uid 48 in /home/virtual/site139/fst/var/www/cgi-bin/includes/upload_class.php on line 155
Back

Here is what they (mediatemple.net) says.
Another alternative, which consists of running php *as* a cgi while processing certain php scripts. This runs php with safe mode off, but as a separate process and as your user. Your php scripts will take a small performance hit when running in cgi mode compared to running in the 'normal' way, so we only suggest using this method on the scripts that need non-safe mode access.

1. Create a directory in which you'll place your php scripts that you want to have run in CGI mode. For this example, we'll use 'phpcgi'
2. In that directory, create a .htaccess file (KB article: What is an .htaccess file) with the following contents:

Action php-script /interpreters/php-script
AddHandler php-script .php
AddHandler php-script .php3

Any php scripts that you place in that directory will now be executed by cgi-mode php.

NOTES:

The workaround method listed in this document may not work correctly with all scripts or with alternate domains. In that case the most viable options include:

* Rewriting the script as CGI which doesn't have safe mode restrictions
I tried creating a .htaccess file like they mentioned, but it still didn't work.

Here is the part of my code that attemps to move the file, I'm using Easy PHP Upload ver. 2.31 from finalwebsites.

Code:
     [LEFT]if (move_uploaded_file($tmp_file, $newfile)) {
    umask(0);
    chmod($newfile , 0644);
    return true;
} else {
    return false;
}[/LEFT]
I guess I need a cgi script to do this. Can someone help me out with this. I don't remember much Perl anymore and I don't know how to integrate it with the PHP. Can I use a perl module to just do the moving called from within my PHP script?

Thanks
 


that's really strange. Safe Mode shouldn't be blocking file uploads, not even on a shared host. I never ran into this problem on reseller zoom or even dreamhost (both shared)

are you sure you did the htaccess bit right? maybe email them and tell them you followed their instructiosn but it still wont' work
 
The files upload fine, it's after they are uploaded I can't move them or copy them to a permanant location. Aparently the file or directory or both are owned by the os or root or something and my script doesn't have permission.

I'll email them and see WTF is up.

If I have to do the move with perl do you know how I can call a perl script with php and get a return value? Seems like running it as a cgi wouldn't be any more secure.

Thanks
 
I think I have it fixed. Aparently, even with the .htaccess it didn't like the fact that my directories were created by a script. I deleted one and created it through ftp and it seems to be working. I'll have to re-create all 50+ others and do a little testing, but I think everything will be ok.
 
I'm willing to bet the problem is not the script but the permissions that are set for the directory that you are trying to write to, set the directory permission bits to 765 an i bet it'll work fine
 
Status
Not open for further replies.