Jump to content

[SOLVED] Need help with upload form


deansaddigh

Recommended Posts

Hi guys, basically im making an upload form for user avatars.

I am adding the avatar details to the user table.

 

my php code doesnt do anything and im not really sure why.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="icon" type="image/gif" href="../site icon/animated_favicon1.gif">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Lifey/Home</title>
<!-- Css style sheet with form part 1-->

        <link href="../css/layout.css" rel="stylesheet" type="text/css" />

<?php
/********************Db connection***********************************/
include '../db/connection.php';
?>

</head>

<body>
<!--top links -->
  	<?php 
   		include "../includes/homepage_top_nav.php";
  	?>

<!-- Container div-->
<div id="container">
   		
        <!-- puffin image-->
    	<div id="puffin_image"></div>
    
        <!-- absolute positioned time and date--> 
        <div id="dt">
            <?php 
			echo date("l, F dS Y g:i:s a ") 
		?>
	</div>
     
	<!-- Logo -->
  		<div id="logo"></div>
     
    	<!--contents-->
     	<div id="contents">
        
		<form method="post" enctype="multipart/form-data">
            <p> Please use this form to upload your avatar</p>            															
		<fieldset class="login">
            <legend>Avatar Upload</legend>
		<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
		<input name="userfile" type="file" id="userfile"> 
		</fieldset>
            </form>

			<?php
				if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
				{
				$fileName = $_FILES['userfile']['name'];
				$tmpName  = $_FILES['userfile']['tmp_name'];
				$fileSize = $_FILES['userfile']['size'];
				$fileType = $_FILES['userfile']['type'];

				$fp      = fopen($tmpName, 'r');
				$content = fread($fp, filesize($tmpName));
				$content = addslashes($content);
				fclose($fp);

				if(!get_magic_quotes_gpc())
				{
					$fileName = addslashes($fileName);
				}

				include 'library/config.php';
				include 'library/opendb.php';

				$query = "INSERT INTO upload (name, size, type, content ) ".
				"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

				mysql_query($query) or die('Error, query failed');
				include 'library/closedb.php';

				echo "<br>File $fileName uploaded<br>";
				}
                ?>

            

        
        
        
        </div>
        
    	<?php 
 		include"../includes/homepage_footer_links.php";
   		?> 


       
  <!-- End Container div-->    
  </div>
    



</body>
</html>

 

Any one have any ideas its prob really simple but i cant for the life of me figure it out.

 

Also can anyone say if this is the best way to do this, as i got this code from a website

Link to comment
https://forums.phpfreaks.com/topic/162904-solved-need-help-with-upload-form/
Share on other sites

your form doesn't have an action...?

i.e. it should be something like (if the data should be posted to itself)

<form method="post" enctype="multipart/form-data" action="<?php echo basename($_SERVER['PHP_SELF']); ?>">

 

otherwise set action="rarqara.php" to whatever page the data should b posted to.

 

and theres no submit button?!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.