Jump to content

$_FILE Error


ProcalX

Recommended Posts

I'm trying to use a php / mysql file upload using the $_FILE global but am having issues.

 

Here is my code:

<?php
session_start();
include "functions.php";
write_head();
?>
<?php
/* Array to hold error data when user fails to enter variables
into required boxes */
$errors = array();

if (isset($_POST['submit']) && $_POST['submit'])
{
/* Get all posted data & protect against sql injection */
$isadmin = htmlentities($_POST["membertype"], ENT_QUOTES);
$username = htmlentities($_POST["username"], ENT_QUOTES);
$password = htmlentities($_POST["password"], ENT_QUOTES);
$firstname = htmlentities($_POST["firstname"], ENT_QUOTES);
$surname = htmlentities($_POST["surname"], ENT_QUOTES);
$email = htmlentities($_POST["email"], ENT_QUOTES);
$day = htmlentities($_POST["dayofbirth"], ENT_QUOTES);
$month = htmlentities($_POST["monthofbirth"], ENT_QUOTES);
$year = htmlentities($_POST["yearofbirth"], ENT_QUOTES);
$shirtnumber = htmlentities($_POST["shirtnumber"], ENT_QUOTES);
$position = htmlentities($_POST["playerposition"], ENT_QUOTES);
$subteam = htmlentities($_POST["subteam"], ENT_QUOTES);
$height = htmlentities($_POST["height"], ENT_QUOTES);
$weight = htmlentities($_POST["weight"], ENT_QUOTES);
//$pic= htmlentities($_POST['image'], ENT_QUOTES);

/* Variable Check */
if (empty($_POST["membertype"])) { array_push($errors, 'Error: You did not submit a usertype.');	}
if (empty($_POST["username"])) { array_push($errors, 'Error: You did not submit a username.');	}
if (empty($_POST["password"])) { array_push($errors, 'Error: You did not submit a password.');	}
if (empty($_POST["firstname"])) { array_push($errors, 'Error: You did not submit a user name.');	}
if (empty($_POST["surname"])) { array_push($errors, 'Error: You did not submit a user surname.');	}
if (empty($_POST["dayofbirth"])) { array_push($errors, 'Error: You did not submit a day of birth.');	}
if (empty($_POST["monthofbirth"])) { array_push($errors, 'Error: You did not submit a month of birth.');	}
if (empty($_POST["yearofbirth"])) { array_push($errors, 'Error: You did not submit a year of birth.');	}
if (empty($_POST["playerposition"])) { array_push($errors, 'Error: You did not submit a user position.');	}
if (empty($_POST["subteam"])) { array_push($errors, 'Error: You did not submit a member team.');	}
if (empty($_POST["height"])) { array_push($errors, 'Error: You did not submit a member height.');	}
if (empty($_POST["weight"])) { array_push($errors, 'Error: You did not submit a member weight.');	}
//if (empty($_POST['image'])) { array_push($errors, 'Error: You did not submit a member picture.');	}

foreach($errors as $e)
{
	echo $e;
	echo "<br />\n";
}

if (sizeof($errors) == 0)
{

	//This is the directory where images will be saved 
	 $target = "images/profiles"; 
	 $target = $target . basename($_FILES['image']['username']);

	 //This gets all the other information from the form 
	 $name=$_POST['username']; 
	 $pic=($_FILES['image']['username']);

	$check1 = mysql_query("SELECT * FROM rh_users WHERE username='$username'");
	if (mysql_num_rows($check1)>0)
	{
		echo "The username '$username' already exists, choose an alternative.";
	}
	else
	{
		mysql_query("INSERT INTO rh_users (id,isadmin,username,password,firstname,surname,email,day,month,year,posts,joined,number,position,subteam,height,weight,image) VALUES ('','$isadmin','$username','$password','$firstname','$surname','$email','$day','$month','$year','0',NOW(),'$shirtnumber','$position','$subteam','$height','$weight','$pic')");
		/* Write photo to the server */
		if (move_uploaded_file($_FILES['image']['tmp_name'], $target))
		{
			/* Check */
			echo "The file ". basename( $_FILES['uploadedfile']['username']). "
			has been uploaded, and your information has been added to the directory.";

			echo "Registration succesful. <a href='admin_cp.php'>Click here to return to the Admin Control Panel</a>.";
		}
		else
		{
			echo "Sorry, there was a problem uploading your file.";
		}
	}
}
}
else
{
echo "You have not submitted data into all the fields, all fields are required for user registration.";
}
?>
<?php
write_footer();
?>

 

I am receiving these errors:

Notice: Undefined index: username in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 56

 

Notice: Undefined index: username in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 60

 

Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 71

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php509A.tmp' to 'images/profiles' in C:\xampp\htdocs\redhawks\admin_registeruser2.php on line 71

Sorry, there was a problem uploading your file.

Link to comment
Share on other sites

username is not part of the FILE variable, but seperate, perhaps you are looking for name? to get file name.

and because it doesnt exist the move file, becomes just a directory, as the file name isnt on the end location

 

replace all $_FILES['uploadedfile']['username'] with $_FILES['uploadedfile']['name'] might fix it

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.