image can't be uploaded from some computer

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
mekya
Forum Newbie
Posts: 9
Joined: Mon Mar 27, 2006 3:10 am

image can't be uploaded from some computer

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

We can't tell you that specifically without seeing your code.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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..
mekya
Forum Newbie
Posts: 9
Joined: Mon Mar 27, 2006 3:10 am

Post 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
Last edited by mekya on Tue Mar 28, 2006 11:13 am, edited 1 time in total.
jrd
Forum Commoner
Posts: 53
Joined: Tue Mar 14, 2006 1:30 am

Post 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.
mekya
Forum Newbie
Posts: 9
Joined: Mon Mar 27, 2006 3:10 am

Post 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?
jrd
Forum Commoner
Posts: 53
Joined: Tue Mar 14, 2006 1:30 am

Post 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.
mekya
Forum Newbie
Posts: 9
Joined: Mon Mar 27, 2006 3:10 am

Post 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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply