Page 1 of 1

image can't be uploaded from some computer

Posted: Mon Mar 27, 2006 10:31 pm
by mekya
hello,

i wrote a script that it upload a jpg image and then
it save the image in mysql table...

in my computer there is no problem all image can be uploaded succesfully,
but some of the other computers there is a problem.
they can't upload any image ...

what causes this problem?

Posted: Mon Mar 27, 2006 11:04 pm
by feyd
We can't tell you that specifically without seeing your code.

Posted: Tue Mar 28, 2006 2:15 am
by onion2k
Are you checking it's a Jpeg using the MIME type reported in $_FILES? Coz IE doesn't send the same as Firefox..

Posted: Tue Mar 28, 2006 10:53 am
by mekya
Here is my code...

Code: Select all

if ($_FILES['foto']['type']!="image/pjpeg")
{
          echo "<script language=javascript>
	    alert('Dosyaniz uygun formatta degil.Dosyanizi jpg formatinda gönderiniz.');
	    self.history.back();					
	  </script>";
           exit;
} 
else if ($_FILES['foto']['size']>500000)
{
	echo "<script language=javascript>
				alert('Dosyanizin boyutu çok büyük 500KB küçük dosyalar gönderiniz ');
				self.history.go(-1);					
		 </script>";
	exit;
}	

$resim=addslashes(fread(fopen($_FILES['foto']['tmp_name'],"r"),filesize($_FILES['foto']['tmp_name'])));	
$aciklama=addslashes($_POST['aciklama']);
$today = getdate();	
$date="$today[year]-$today[mon]-$today[mday]";
$sql="insert into ".$tablo_fotograf."
	 (okul_kodu,Resim,Aciklama,Tarih) values
	 ('".$okul_kodu."', '$resim' , '$aciklama' , '$date')";
$tpl->define(fotogonder_durum ,"durum.tpl");
	
if ( $db->query( $sql ) ) 
{
	$tpl->assign( MESAJ , "Gönderdiðiniz fotoðraf kaydedilmistir." );
	$mesaj="merhaba\n".
		"\nwww.e-yillik.net te ki yilliga $aciklama diye aciklamasi olan yeni fotograf eklendi.\n".
		"\nBilgilerinize sunulur.\n".
		"\nIyi gunler...\n".
		"\nwww.e-yillik.net/yonetim/?okul=$okul_kodu ";
               @mail( $yonetici_mail , "Fotograf eklendi" , $mesaj ,"from:info@e-yillik.net");
}		
else
{
	$tpl->assign( MESAJ , "Gönderdiðiniz fotoðraf kaydedilemedi.<br>")
}
	$tpl->parse( fotogonder_durum , "fotogonder_durum" );
	$tpl->FastPrint( fotogonder_durum );

i send a file to this page and some computer can't save this image file into the mysql table

Posted: Tue Mar 28, 2006 11:08 am
by jrd
onion2k wrote:Are you checking it's a Jpeg using the MIME type reported in $_FILES? Coz IE doesn't send the same as Firefox..
Is that the whole code? Could be the browser or the version, could be user rights, since it works on some and not on others.

Posted: Tue Mar 28, 2006 11:11 am
by mekya
this is not whole code...

i check user rights but i don't check browser or the version?

how must i do that?

Posted: Tue Mar 28, 2006 11:22 am
by jrd
try using the same browser with the same version on your computers, for example test with IE6 and make sure your javascript is not disabled under the security settings. see if it works first.

Posted: Tue Mar 28, 2006 11:48 am
by mekya
yes i tried no problem,
javascript is not disabled...

also one says that
although i upload the jpeg image,

it doesn't pass the first "if" that control the image is a jpeg or not...

Posted: Tue Mar 28, 2006 12:52 pm
by feyd
image/pjpeg is just one of the mime types JPEG files can come in on and you should never rely on the browser to tell you what type of file it is.

Use getimagesize() to determine that it is an image and if it is a type you want to accept. Use file_get_contents() instead of fopen()-fread(), if possible, it's just easier to work with. addslashes() alone may not be enough to avoid injection problems. If you're using MySQL, use mysql_real_escape_string() instead.