Jump to content

Image uploading

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
the form
	<form action='process.php' name='form1' method='post'>
	  <table width='470' border='0' cellspacing='1' cellpadding='0' id='profile_table'>
	  	<tr bgcolor='#333333'>
		  <td width='100' height='25' id='profile_table'><div align='right'>Main Game: </div></td>
		  <td height='25' id='profile' style='padding-left:30px;'>
		  <input name='MAX_FILE_SIZE' value='2097152' type='hidden'>
		  <input name='image' type='file' size='34' accept='image/jpeg, image/gif, image/png'>
		  </td>
		</tr>
</table>
</form>




process.php

		if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

			// Temporary file name stored on the server
			$tmpName  = $_FILES['image']['tmp_name'];
			
			// Read the file 
			$fp      = fopen($tmpName, 'r');
			$data = fread($fp, filesize($tmpName));
			$data = addslashes($data);
			fclose($fp);
			$config->query("UPDATE `members` SET picture = '$data' WHERE username = '$username'");
		}


but the isset($_FILES['image']) is not working its saying its not set..

#2
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
What does:

accept='image/jpeg, image/gif, image/png'>

do? I've never heard of that before. I can't really see anything wrong. Maybe it's because of the accept attribute?

#3
Whitey

Whitey

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 255 posts
That has it accpeting only images that are jpeg gif and png

EDIT: figured it out i was missing ENCTYPE in my form tag

#4
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
Well even without enctype, I wasn't getting any errors so I have no idea. :s

Glad you got it figured out. Since it's using a class and databases, I thought maybe a problem with the class or database.

#5
Guest_Jaan_*

Guest_Jaan_*
  • Guests

Whitey said:

That has it accpeting only images that are jpeg gif and png

EDIT: figured it out i was missing ENCTYPE in my form tag

yes.. you have to have this enctype.. like this:

<form action="upload.php" method="post" enctype="multipart/form-data">

<input type="file" name="file" /><br />

<input type="submit" value="Upload" />

</form>