PDA

View Full Version : image upload problem



mskocabay
09-05-2007, 04:26 PM
my code is


<?php

session_start();
include_once('lib/mysql.php');

$PictMaxSize=30720;
$klasor = "member/pictures/";
$resim=$_FILES['resim']['name'];
$newfile = $klasor.$resim;
$tur=$_FILES['resim']['type'];
$boyut=$_FILES['resim']['size'];
if(isset($_FILES['resim']))
{

if($boyut>$PictMaxSize)
{
echo ("<SCRIPT LANGUAGE='JavaScript'> alert ('Resim Boyutu BŁyŁk'); </SCRIPT>");
exit;
}
if ($tur != "image/gif" and $tur != "image/jpeg" and $tur != "image/pjpeg" and $tur != "image/x-png")
{
echo ("<SCRIPT LANGUAGE='JavaScript'> alert ('Farkli Format'); </SCRIPT>");
exit;
}

$my=new Mysql();
$sql="SELECT user_id from picture where user_id='115'";
$soru =$my->query($sql);
$cevap = $my->fetch($soru);
$adet=$my->numRows($soru);
if ($adet=="0" || $adet=="")
{
$sql2="insert into picture (user_id,picture1,statu1)values('115','$resim','0')";
$yaz=$my->query($sql2);
}
else
{
$say=1;
for ($say=1; $say<6; $say++)
{
if (!isset($cevap['picture'.$say]))

{
$sql3="update picture set picture.$say='$resim' where user_id='115'";
$yaz2=$my->query($sql3);
}
}
}


i want that in my database there were 5 fields about picture.

picture1 , picture2 , picture3 , picture4 , picture5;

if there is no picture for user insert into picture1 if picture1 is not null insert into picture2 or picture2 is not null insert into picture3.

in my db
user_id | picture1 | picture2 | picture3 | picture4 | picture5 |

115 | logo.jpg | logo2.jpg

i want this but with my code

user_id | picture1 | picture2 | picture3 | picture4 | picture5

115 | logo.jpg
115 | logo2.jpg

and numRows function in mysql.php

function numRows($resultSet)
{
$rows = mysql_num_rows($resultSet);
if ($rows == null)
return $this->mysqlRaiseError();
return $rows;
}



sorry for my bad english

rafiki
09-05-2007, 04:46 PM
how can you expect an image to be multiple formats at the same time


if ($tur != "image/gif" and $tur != "image/jpeg" and $tur != "image/pjpeg" and $tur != "image/x-png")
should be using OR but i preffer using || (which is or)


if ($tur != "image/gif" || $tur != "image/jpeg" || $tur != "image/pjpeg" || $tur != "image/x-png")
thats the first thing i seen wrong.

Pennimus
09-05-2007, 05:01 PM
Ahem, that code is saying "if the image is NOT x, y or z" :thumbsup:

mskocabay
09-05-2007, 05:05 PM
i want help about image upload :(

rafiki
09-05-2007, 05:12 PM
Ahem, that code is saying "if the image is NOT x, y or z" :thumbsup:

its meant to.

Mwnciau
09-05-2007, 05:41 PM
if ($tur != "image/gif" || $tur != "image/jpeg" || $tur != "image/pjpeg" || $tur != "image/x-png")

That will always return true, I think thats what pennimus was trying to point out.

rafiki
09-05-2007, 05:47 PM
not really if they try uploading something like bmp / or non image file.
then in returns false. stopping the upload.

Mwnciau
09-05-2007, 05:50 PM
Ok for the BMP example:

$tur != "image/gif" - returns true so the if() returns true

Another example, image/gif:

$tur != "image/gif" - returns false
$tur != "image/jpeg" - returns true so the if() returns true

Pennimus
09-05-2007, 11:18 PM
@ Rafiki, I was just getting at the fact that you said "how can you expect an image to be multiple formats at the same time", when the code was not saying that.