Forum Moderators: coopster

Message Too Old, No Replies

Debugging a pdf uploader

         

GGR_Web

8:52 pm on Jul 27, 2009 (gmt 0)

10+ Year Member



Hi
If you could help me keep my sanity that would be great.

I'm using mamp to run my mac as a test server for the following code - which is part of a wordpress theme. I'm using version 2.6.2.

@$upload_Name = $_FILES['upload']['name'];
@$upload_Size = $_FILES['upload']['size'];
@$upload_Temp = $_FILES['upload']['tmp_name'];
@$upload_Mime_Type = $_FILES['upload']['type'];

if( $upload_Size == 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid upload</font></p>");
}
if( $upload_Size >5000000)
{
//delete file
unlink($upload_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid upload</font></p>");
}
if( $upload_Mime_Type != "application/pdf")
{
unlink($upload_Temp);
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid upload</font></p>");
}
$uploadFile = "uploads/".$upload_Name ;
if (!is_dir(dirname($uploadFile)))
{
@RecursiveMkdir(dirname($uploadFile));
}
else
{
@chmod(dirname($uploadFile), 0777);
}
@move_uploaded_file( $upload_Temp , $uploadFile);
chmod($uploadFile, 0644);
// Change This....
$upload_URL = "http://localhost:8888/wordpress/uploads/".$upload_Name ;

?>

I've done everything I can think of to validate the code. I've checked the form is actually passing the variables. I've checked the validation procedure.
Now I'm thinking (or rather hoping) that its something to do with my testing enviroment - but I don't understand every single line of the code, so its hard to know.

Could you please look it over for me and see if the code is failing somewhere.

Also, can a mamp server/wordpress setup handle this type of operation?

jatar_k

2:49 pm on Jul 28, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I assume it fails but you didn't explain how or if you get an error message.

What actually happens?
does the file not get moved?
does it die silently?
does nothing happen after you submit the form?

we can't really test this code, I don't even have wordpress, but with a little more data we might be able to give some ideas

GGR_Web

6:16 pm on Jul 28, 2009 (gmt 0)

10+ Year Member



Right. I dumped this code into a pre-existing form processing script that validates the rest of the fields (name, email address pdf title & description) and sends them via the mail function to the site administrator, for consideration. This part all works as expected.

As of now, all the file upload values are successfully passed to the proccessor. All the validation checks appear to be passed successfully - the thank you page appears as expected, but the pdf does not upload either into the temporary location or the pernament one. My best guess is that the script is dying somewhere after the final die statement. Actually I'll test that and post the result.

jatar_k

11:58 am on Jul 29, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



try removing all the @ as well, those suppress errors so it might be giving an error that you aren't seeing