Jump to content

Simple Image Uploader Gone Wrong


wildbuddha

Recommended Posts

Hi everyone.  Thanks, in advance, for any and all help!  I'm sure there's something simple I'm missing as I'm very new to PHP.

function uploadAttachment()
{
	if(isset($_POST['submitAttachment']))
	{
		if ($File)    
		{
    		copy ($File, "$File_name");
			$db_hostname = "localhost"; 
			$db_username = "root";
			$db_password = "";
			$db_name =     "justinalba_module3_db";
			$dbc = @mysqli_connect($db_hostname, $db_username, $db_password, $db_name)
   	 		or die("Unable to connect to MySQL");
			$username = $_POST['userName'];
			$id=$_POST['id'];
			$sql="UPDATE user SET avatarURL='$File_name' WHERE name_username='$username' AND id='$id'";
			$query=mysqli_query($dbc,$sql) or die();
			$sql2="SELECT * FROM user WHERE name_username='$username' AND id='$id'";
			$query2=mysqli_query($dbc,$sql2) or die();
			if($query)
			{
				
				echo "You uploaded the following photo:";
				echo "<img src=\"";
				echo $File_name;
				echo "\" width=\"400px\">";
				unlink ($File);
			}
			else
				{
					echo "You did not upload a file.";
				}
		}
		
	}
}

 

The above code is giving me an error:

"Notice: Undefined variable: File in /Users/justinalba/Sites/php-class/module3/functions.php on line 257"

 

How come the variable can be found on line 255 but not 257?  Do I need to declare $File as something?

 

Thanks.

Link to comment
Share on other sites

Line 257 in your code above is this

 

{

 

Which is between the two lines that reference $File. Are you sure the error is not on the first instance? Try putting in some echo statements to verify

 

 

echo "Before the if()<br>\n";
if ($File)
{
    echo "After the if()<br>\n";
   copy ($File, "$File_name");
   echo "After the copy()<br>\n";
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.