Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    image upload problem

    my code is
    Code:
    <?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
    Code:
    function numRows($resultSet)
    	{
    	   $rows = mysql_num_rows($resultSet);
    	   if ($rows == null) 
    	     return $this->mysqlRaiseError();
    	 return $rows;
    	}


    sorry for my bad english
    Last edited by mskocabay; 09-05-2007 at 04:39 PM. Reason: adding function

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    how can you expect an image to be multiple formats at the same time
    PHP Code:
    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)
    PHP Code:
    if ($tur != "image/gif" || $tur != "image/jpeg" || $tur != "image/pjpeg" || $tur != "image/x-png"
    thats the first thing i seen wrong.

  • #3
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    Ahem, that code is saying "if the image is NOT x, y or z"

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    i want help about image upload

  • #5
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by Pennimus View Post
    Ahem, that code is saying "if the image is NOT x, y or z"
    its meant to.

  • #6
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    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.

  • #7
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    not really if they try uploading something like bmp / or non image file.
    then in returns false. stopping the upload.

  • #8
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    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

  • #9
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts
    @ 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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •