Hi, I am really struggling with a file upload script could someone give it a look over for me and pehaps help me out?
The script outpust the following error:
B]Uploaded file is 0 length.[/B]
This error message is created ifrom the scripts error checking from the following code:
if ($PromoFlyer_eve_size == 0) {
echo 'Problem: Uploaded file is 0 length.';exit;}
Below is the entire script.. Could it be because I am trying to create the upload script using $PHP_Self? does the upload require that I pass through to a new PHP file?
Thanks
<?
$form_block = '
<html>
<head>
<title>Add Event</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<form enctype="multipart/form-data" method="post" action="'.$PHP_SELF.'">
<input name="op" type="hidden" value="ds">
<br>Promotion Name<br><input name="PromoName_eve" type="Text" id="PromoName_eve" size="40" value="'.$_POST[PromoName_eve].'">
<br>Promotor Name<br><input name="PromoTor_eve" type="Text" id="PromoTor_eve" size="40" value="'.$_POST[PromoTor_eve].'">
<br> Promotion Date<br> <input name="PromoDate_eve" type="Text" id="PromoDate_eve" size="25" value="'.$_POST[PromoDate_eve].'">
<br>Promotion Time<br><input name="PromoTime_eve" type="Text" id="PromoTime_eve" size="40" value="'.$_POST[PromoTime_eve].'">
<br>Promotion Copy<br><input name="PromoBlurb_eve" type="Text" id="PromoBlurb_eve" size="40" value="'.$_POST[PromoBlurb_eve].'">
<br>Dresscode<br><input name="PromoDresscode_eve" type="Text" id="PromoDresscode_eve" size="25" value="'.$_POST[PromoDresscode_eve].'">
<br>Price<br><input name="PromoPrice_eve" type="Text" id="PromoPrice_eve" size="25" value="'.$_POST[PromoPrice_eve].'">
<br>Event Graphic<br><input type="File" name="PromoFlyer_eve" size="25" >
<br>
<br>
<input type="submit" name="submit" value="Upload">
</form>
';
if ($_POST['op'] != "ds") {
// they need to see the form
echo "op is not equal to ds";
echo "$form_block";
}
else if ($_POST['op'] == "ds") {
if (empty($_POST['PromoName_eve'])) {
$PromoName_err = "<font color=red>Please Enter the Event or Promotion Name!</font><br>";
$Send = "no";
}
if ( empty($_POST['PromoTor_eve'])) {
$PromoTor_err = "<font color=red>Please the Event Promoter!</font><br>";
$Send = "no";
}
if ( empty($_POST['PromoDate_eve'])) {
$PromoDate_err = "<font color=red>Your Event must have a Date!</font><br>";
$Send = "no";
}
if ( empty($_POST['PromoBlurb_eve'] )) {
$PromoBlurb_err = "<font color=red>You Need enter some event copy!</font><br>";
$Send = "no";
}
if ( empty($_POST['PromoDresscode_eve'] )) {
$PromoDresscode_err = "<font color=red>Please enter the event dresscode!</font><br>";
$Send = "no";
}
if ($Send != "no") {
//ok to send!
## Upload Image
$PromoFlyer_eve = $HTTP_POST_FILES['$PromoFlyer_eve']['tmp_name'];
$PromoFlyer_eve_name = $HTTP_POST_FILES['$PromoFlyer_eve']['name'];
$PromoFlyer_eve_size = $HTTP_POST_FILES['$PromoFlyer_eve']['size'];
$PromoFlyer_eve_type = $HTTP_POST_FILES['$PromoFlyer_eve']['type'];
## $$PromoFlyer_eve_error = $HTTP_POST_FILES['$PromoFlyer_eve']['error'];
if ($PromoFlyer_eve == 'none') {
echo 'Problem: No File Uploaded.';exit; }
if ($PromoFlyer_eve_size == 0) {
echo 'Problem: Uploaded file is 0 length.';exit;}
if ($PromoFlyer_eve_type != 'image/jpeg') {
echo 'Problem: Uploaded file is Not a JPEG.';exit;}
//Put the file into the images dir
$upfile='/home/public_html/adminPHP/images/'.$PromoFlyer_eve_name;
if (is_uploaded_file($PromoFlyer_eve))
{
if (!move_uploaded_file($PromoFlyer_eve, $upfile)){
echo 'Problem: Could not move file to destination directory'; exit; }
}
else
{
echo 'Problem:Possible file upload attack. Filename: '.$PromoFlyer_eve_name;
exit;
}
echo 'File Upladed Success<br /><br />';
## Database Variables
$user = "user";
$pass = "pass";
$db = "dbname";
$PromoName_eve = $_POST['PromoName_eve'];
$PromoTor_eve = $_POST['PromoTor_eve'];
$PromoDate_eve = $_POST['PromoDate_eve'];
$PromoTime_eve = $_POST['PromoTime_eve'];
$PromoBlurb_eve = $_POST['PromoBlurb_eve'];
$PromoDresscode_eve = $_POST['PromoDresscode_eve'];
$PromoPrice_eve = $_POST['PromoPrice_eve'];
$PromoFlyer_eve = $_POST['PromoFlyer_eve'];
## Database Connection
$cnxion = mysql_connect( "localhost", $user, $pass );
if ( ! $cnxion ) die( "Couldn't connect to MySQL" );
mysql_select_db( $db, $cnxion ) or die ( "Couldn't open database: ".mysql_error() );
$query = "INSERT INTO Events_eve SET promoName_eve = '$PromoName_eve', promoTor_eve = '$PromoTor_eve', promoDate_eve = '$PromoDate_eve', promoTime_eve = '$PromoTime_eve', promoBlurb_eve = '$PromoBlurb_eve', promoDresscode_eve = '$PromoDresscode_eve', promoPrice_eve = '$PromoPrice_eve', promoFlyer_eve = '$PromoFlyer_eve_name'";
mysql_query( $query, $cnxion ) or die ( "Couldn't add data to the Database table: ".mysql_error() );mysql_close( $cnxion );
## redirect to next page
## header("Location: [url http://www.blah.com/adminPHP/success.php[/url]");
}
else if ($Send == "no"){
echo "$PromoName_err";
echo "$PromoTor_err";
echo "$PromoDate_err";
echo "$PromoBlurb_err";
echo "$PromoDresscode_err";
echo "$PromoFlyer_err_err";
echo "$form_block";
}
}
?>