EvilSupahFly
08-19-2011, 04:40 AM
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:
<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'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:
<?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! I've posted this in both Apache and PHP because I'm not sure where the problem is.
<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'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:
<?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! I've posted this in both Apache and PHP because I'm not sure where the problem is.