PDA

View Full Version : php upload script not working


peacock
04-03-2007, 11:15 PM
Can anyone please help me I have been trying to do this for days! I have created a form in dreamweaver 8 with an upload function. The form function is “post” and the Enctype is “multipart/form-data”. The page is located at http://www.theonebigad.com/details_banner.html (http://www.theonebigad.com/details_banner.html). I have tried for ages to work out the php script to get the form to work however eventually gave in and bought phpformwizard, thinking that would be my solution, however I now can’t get this to work! (My host does accept php and I got the wizard working without the file upload part.)

The upload directory is http://www.theonebigad.com/bannerupload/ (http://www.theonebigad.com/bannerupload/) there is a file size limit of 250kb and it only allow jpegs and gifs. At the moment there is no form validation other than that to make it easier to work out how to do it. The php script is as follows:
<?php
# ----------------------------------------------------
# -----
# ----- This script was generated by PHP-Form Wizard 1.2.5 on 03/04/2007 at 23:50:04
# -----
# ----- http://www.tools4php.com
# -----
# ----------------------------------------------------

// Receiving variables
@$pfw_ip= $_SERVER['REMOTE_ADDR'];
@$file_Name = $_FILES['file']['name'];
@$file_Size = $_FILES['file']['size'];
@$file_Temp = $_FILES['file']['tmp_name'];
@$file_Mime_Type = $_FILES['file']['type'];
function RecursiveMkdir($path)
{
if (!file_exists($path))
{
RecursiveMkdir(dirname($path));
mkdir($path, 0777);
}
}

// Validation
if( $file_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid file</font></p>");
}
if( $file_Size >600000)
{
//delete file
unlink($file_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid file</font></p>");
}
if( $file_Mime_Type != "image/gif" AND $file_Mime_Type != "image/jpeg" )
{
unlink($file_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid file</font></p>");
}
$uploadFile = $file_Name ;
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $file_Temp , $uploadFile);
chmod($uploadFile, 0644);
$file_URL = "http://www.theonebigad.com/bannerupload/".$file_Name ;
//Sending Email to form owner
$pfw_header = "From: $file\n"
. "Reply-To: $file\n";
$pfw_subject = "form submission";
$pfw_email_to = "richard.stratton@ic.ac.uk";
$pfw_message = "Visitor's IP: $pfw_ip\n"
. "file: $file_URL\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
echo("<p align='center'><font face='Arial' size='3' color='#FF0000'>thanks</font></p>");
?>


Basically whenever I try and click to submit it just comes up with “please enter a valid file” which is the error message. Despite the file being a jpeg and below the size limit.

Can anyone help me with this it would be so appreciated.

Thanks,

Rich

domedia
04-04-2007, 12:02 AM
Give the company a call, they should give some kind of support on commercial software. (I don't know PHP, but the people that sold it to you could at least make sure it's working.)

Anyone see what's going on on the page?

davidj
04-04-2007, 07:27 AM
you need to debug this script

where you have your warning messages in IF statements

if( $file_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid file</font></p>");
}



you need to add a trace to see where the script is failing (NOTE the error message. Just add a different message to each IF condition so you know where its droping out.

if( $file_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>error here .......Please enter a valid file</font></p>");
}

peacock
04-04-2007, 08:52 AM
Thanks very much for your help. Okay I have been playing around with this more and think I have worked out 2 key problems. I didn't realise that you get different file names for JPEGS and GIFs etc (eg, JPG, JPEG etc) so I have corrected that, now however the is one more problem:

I can actually get it to work and it uploads the "banner" file to my public_html folder but everytime it does this it alters the permissions on my "php" folder (just the folder on my public_html where I have located the php script). The result is it changes its from 755 to 777. Then if I try and submit another banner it comes up with the following:

"Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@theonebigad.com (webmaster@theonebigad.com) and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Apache/1.3.37 Server at www.theonebigad.com (http://www.theonebigad.com) Port 80"

I'm guessing this is something to do with my hosting company but whenever I speak to them they just say its the php script which is wrong, however I definatley know that does work! Any advice??? Thanks again, Rich

davidj
04-04-2007, 08:58 AM
your script is chmod-ing to 644 after the upload


chmod($uploadFile, 0644);


the issue maybe that you are not allowed to change the permissions or at least apache cant

peacock
04-04-2007, 09:35 AM
Sorry I'm pretty new to all of this; does that mean I need to alter the script? If so could you give me some guidance! Sorry for being quite so ignorant!

Rich

davidj
04-04-2007, 01:52 PM
try changing the chmod to 0777

peacock
04-04-2007, 04:31 PM
Awesome thanks very much! All working now, can finally launch the site! Just want to thank everyone for all their help greatly appreciated!