Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Server Side Upload script fails on Apache 2.2 with PHP5 |
|
Author |
|
EvilSupahFly
Joined: 18 Aug 2011 Posts: 15 Location: 44° 24' N / 79° 38' W
|
Posted: Fri 19 Aug '11 5:54 Post subject: Server Side Upload script fails on Apache 2.2 with PHP5 |
|
|
I'm running Apache 2.2 on WinXP, 32 bit, and I have installed PHP5. I need to enable file uploads to the server, and have the following "submit" HTML:
Code: | <form method="POST" action="uploader_v3.php" enctype="multipart/form-data">
Choose a file to upload:
<input type="file" name="uploaded_file">
<input type="submit" value="Upload File">
</form>
|
The problem is that once the "Submit" button is clicked, the uploader script returns a blank page. I've checked the error and access logs, and they're no help.
I'm not sure if this is a PHP issue or an Apache issue because Apache's .CONF is good to go and PHP.INI has file uploads enabled, and syntactically, there's nothing wrong with the uploader_v3.php script. For those fluent in PHP, here's what "uploader_v3.php" looks like:
Code: | <?PHP
$SafeFile = $HTTP_POST_FILES['uploaded_file']['name'];
$uploaddir = "/uploads/";
$path = $uploaddir.$SafeFile;
$upload_err = $HTTP_POST_FILES['uploaded_file']['error']
if($uploaded_file != none){ //AS LONG AS A FILE WAS SELECTED...
if(copy($HTTP_POST_FILES['uploaded_file']['tmp_name'], $path)){ //IF IT HAS BEEN COPIED...
//GET FILE NAME
$theFileName = $HTTP_POST_FILES['uploaded_file']['name'];
//GET FILE SIZE
$theFileSize = $HTTP_POST_FILES['uploaded_file']['size'];
if ($theFileSize>999999){ //IF GREATER THAN 999KB, DISPLAY AS MB
$theDiv = $theFileSize / 1000000;
$theFileSize = round($theDiv, 1)." MB"; //round($WhatToRound, $DecimalPlaces)
} else { //OTHERWISE DISPLAY AS KB
$theDiv = $theFileSize / 1000;
$theFileSize = round($theDiv, 1)." KB"; //round($WhatToRound, $DecimalPlaces)
}
echo <<<UPLS
<table cellpadding="5" width="300">
<tr>
<td align="Center" colspan="2"><font color="#C80000"><b>Upload Successful</b></font></td>
</tr>
<tr>
<td align="right"><b>File Name: </b></td>
<td align="left">$theFileName</td>
</tr>
<tr>
<td align="right"><b>File Size: </b></td>
<td align="left">$theFileSize</td>
</tr>
<tr>
<td align="right"><b>Directory: </b></td>
<td align="left">$uploaddir</td>
</tr>
</table>
UPLS;
} else {
//PRINT AN ERROR IF THE FILE COULD NOT BE COPIED
echo <<<UPLF
<table cellpadding="5" width="80%">
<tr>
<td align="Center" colspan="2"><font color="#00C800"><b>File "$SafeFile" could not be uploaded:<br>Return Code: $upload_err <br /></b></font></td>
</tr>
</table>
UPLF;
}
}
?> |
Can somebody help me? This is EXTREMELY annoying! |
|
Back to top |
|
James Blond Moderator
Joined: 19 Jan 2006 Posts: 7371 Location: Germany, Next to Hamburg
|
Posted: Sat 20 Aug '11 15:36 Post subject: |
|
|
replace $HTTP_POST_FILES with $_FILES. Turn on error reporting |
|
Back to top |
|
EvilSupahFly
Joined: 18 Aug 2011 Posts: 15 Location: 44° 24' N / 79° 38' W
|
Posted: Tue 18 Oct '11 17:30 Post subject: |
|
|
Did I say "thanks"? I should have. THANKS!! (Sorry it took so long - lost my 'net for a while in favour of paying my rent instead) |
|
Back to top |
|
|
|
|
|
|