uploading file error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

uploading file error

Post by psychotomus »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


it keeps telling me $_FILES["file"]["tmp_name"] is blank so my message to the page is "You must have a file to upload"

I cant figure out why $_FILES["file"]["tmp_name"] keeps turning blank.



here my form

[syntax="html"]
	<form name="form1" method="post" action="">
	  <input name="radiobutton" type="radio" value="msn">
	  Msn Contacts  [<a href="http://www.simsportal.net/help-msn-contacts.php" target="_blank">Help</a>]<br>
	  <table width="100%"  border="0">
		<tr>
		  <td width="20%"><strong>Subject:</strong></td>
		  <td width="80%"><input type="text" name="textfield"></td>
		</tr>
		<tr>
		  <td><strong>Your Message To Them: </strong></td>
		  <td><input type="text" name="textfield2"></td>
		</tr>
	  </table>
	  <input type="file" name="file" id="file">
	  <br>
	  <input type="submit" name="Submit" value="Upload And Mail">
	</form>
below is my php[/syntax]

Code: Select all

if(isset($_POST['Submit']))
{
	//if file not blank
	if (!empty($_FILES["file"]["tmp_name"]))
	{
		//get file type
		$file_typ = array();
		$file_typ =  explode('.',strtolower($_FILES["file"]["name"]));
		$file_type = $file_typ[count($file_typ)-1];
		//if radio button is checked and = MSN
		if($_POST['radiobutton'] == "msn")
		{
			//if file type is msn contact file type
			if (strtolower($file_type) == "ctt" )
			{
				if (!move_uploaded_file($_FILES["file"]["tmp_name"], "contact_uploads/" . $_FILES["file"]["name"]))
				{
					//open file
					$handle = @fopen("contact_uploads/" .$_FILES["file"]["name"], "r");
					if ($handle) 
					{
						$line_counter = 1;
						while (!feof($handle)) 
						{
							$buffer = fgets($handle, 4096);
							$line_counter = $line_counter + 1;
							//skip first 4 lines in file
							if($line_counter == 5)
							{
								//if not last 3 lines in file
								if( strpos($buffer, "</contactlist>") === FALSE && strpos($buffer, "</service>") === FALSE && strpos($buffer, "</messenger>") === FALSE)
								{
									$buffer = trim($buffer);
									$pos = strpos($buffer, ">");
									$buffer =substr($buffer,$pos, strlen($buffer) - $pos - 10);
									echo $buffer. '<br>';
								}
							}
						}
						fclose($handle);
					}
				}
				else
				{
					$eRR = "Could not upload file";
				}
			}
		}
		else
		{
			echo '<strong>You must choose MSN Contacts to continue.';
		}
	}
	else
	{
		echo '<strong>You must have a file to upload';
	}
}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The enctype attribute for the <form> tag is not specified.
Post Reply