Jump to content

Upload Pic


Panta

Recommended Posts

please i'm working on a project that requires a student to register as well as print out his form with passport.The problem i'm having is that those pic with correct format are not accepted, it kept on tellin me that i can only upload gif....., which is meant for a picture that is not of the format required. this is my script

<body><table width="100%" border="0" cellspacing="0" cellpadding="2">  <tr>    <td align="center"><h1><font color="#0000FF" face="Arial">ADD STUDENT PROFILE</font></h1></td>  </tr></table><br><br><table width="100%" border="0" cellspacing="0" cellpadding="2">  <tr>    <td align="right"><font size="1" face="Arial"><a href='main.php'>Student List</a></font></td>  </tr></table><br><br><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" name='s' onsubmit='return validated()';><table width="70%" border="0" align="center" cellpadding="2" cellspacing="2">  <tr>    <td width="33%" align="right"><font size="2" face="Arial"><strong>Matric Number</strong></font></td>    <td width="5%" align="center">:</td>    <td width="62%"><input type='text' name='matric' size=30 maxlength=15></td>  </tr>  <tr>    <td align="right"><font size="2" face="Arial"><strong>Name</strong></font></td>    <td align="center">:</td>    <td><input type='text' name='name' size=30 maxlength=50></td>  </tr>  <tr>    <td align="right"><font size="2" face="Arial"><strong>Course</strong></font></td>    <td align="center">:</td>    <td><input type='text' name='course' size=30 maxlength=50></td>  </tr>  <tr>    <td align="right"><font size="2" face="Arial"><strong>Semester</strong></font></td>    <td align="center">:</td>    <td><input type='text' name='sem' size=5 maxlength=2></td>  </tr>  <tr>    <td align="right"><font size="2" face="Arial"><strong>######</strong></font></td>    <td align="center">:</td>    <td><input type='radio' name='######' value='Male' checked> Male  <input type='radio' name='######' value='Female'> Female</td>  </tr>  <tr>    <td align="right"><font size="2" face="Arial"><strong>Contact Number</strong></font></td>    <td align="center">:</td>    <td><input type='text' name='tel' size=30 maxlength=50></td>  </tr>  <tr>    <td align="right"><font size="2" face="Arial"><strong>Address</strong></font></td>    <td align="center">:</td>    <td><input type='text' name='address' size=50 maxlength=100></td>  </tr>  <tr>    <td align="right"><font size="2" face="Arial"><strong>Picture</strong></font></td>    <td align="center">:</td>    <td>	<input type="hidden" name="MAX_FILE_SIZE" value="10485760">	<input type="file" name="picture"  size="40"> <font size="1" face="Arial"> Maxsize 1MB</font>	</td>  </tr>  <tr>    <td> </td>    <td> </td>    <td><input type='submit' name="submit" value='Submit'> <input type='reset' value='Reset'></td>  </tr></table></form></body></html><?php	$submit=isset($_POST[submit]); 	if ($submit) 	{				include 'database.php';						$data = addslashes(fread(fopen($picture, "r"), filesize($picture)));		$pjpeg="image/pjpeg";		$jpeg="image/jpeg";		$gif="image/gif";		$png="image/png";		$bmp="image/bmp";				if ($picture_type == $pjpeg || $picture_type == $jpeg || $picture_type == $gif || $picture_type == $png || $picture_type == $bmp)		{				$sql="INSERT INTO info (matric, name, course, sem, ######, tel, address ,bin_data,filename,filesize,filetype)			VALUES ('$matric', '$name', '$course', '$sem', '$######', '$tel', '$address', '$data','$picture_name','$picture_size','$picture_type')";		$result=mysql_query($sql);			header ("Location: main.php");		}		else{		echo "<script language='JavaScript'>";		echo "window.alert('Error! You only can upload jpeg, gif, png, bmp file type.')";		echo "</script>"; 		}	}	?>

Link to comment
Share on other sites

$data = addslashes(fread(fopen($picture, "r"), filesize($picture)));
$picture is not set to anything, it's undefined.
if ($picture_type == $pjpeg || $picture_type == $jpeg || $picture_type == $gif || $picture_type == $png || $picture_type == $bmp)
$picture_type is also not set to anything...
$sql="INSERT INTO info (matric, name, course, sem, ######, tel, address ,bin_data,filename,filesize,filetype) VALUES ('$matric', '$name', '$course', '$sem', '$######', '$tel', '$address', '$data','$picture_name','$picture_size','$picture_type')";
I know that the "######" refers to the other word for "gender", but not a single one of those variables in that query are set. You are not setting anything. Look through the form and file upload tutorials. You need to use the $_POST and $_FILES arrays when you're working with form submissions and file uploads.
it kept on tellin me that i can only upload gif
I see no error message in the code that says you can only upload gif, this is the only error message I see in the code:'Error! You only can upload jpeg, gif, png, bmp file type.'Is that the message you're seeing?
Link to comment
Share on other sites

Archived

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

×
×
  • Create New...