1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Problem uploading Digital pics

Discussion in 'PHP' started by cynical_tear, Jul 15, 2010.

  1. #1
    Hello friends,

    This is my website - Snapsvilla

    Its a image uploading website... I allow users to upload there jpeg, gif, and bmp snaps. If a user uploads a snap which does not belong to these three extension it will show "Unsupported file format"...

    There seems to be a problem because whenever user uploads a snap clicked from DIGITAL CAM, it shows "unsupported file format" but the file is of JPEG formant.. When I upload the snaps clicked from mobile then it works fine.. Am unable to locate the problem with my code... Please suggest...


    
    
    $name1 = $_FILES['snap1']['name'];
    $size1 = $_FILES['snap1']['size'];
    $type1 = $_FILES['snap1']['type'];
    $temp1 = $_FILES['snap1']['tmp_name'];
    $error1 = $_FILES['snap1']['error'];	
    		
    if($name1)
    {
    	if($size1 <= 5000000)
    	{
    		if($type1 == 'image/jpeg' || $type1 == 'image/pjpeg' || $type1 == 'image/gif' || $type1 == 'image/bmp' || $type1 == 'image/png')
    		{
    			$save_as	= $name1;
    			$location = "uploadedsnaps/".$save_as;
    			move_uploaded_file($temp1,$location);
    					
    			$album_snap = mysql_query("SELECT * FROM snaps WHERE albumid='$albumid'");
    			$album_rows = mysql_num_rows($album_snap);
    
    			if($abum_rows == 0)
    			{
    			  $album_dp = mysql_query("UPDATE album SET cover='$location' WHERE albumid='$albumid'");
    			}
    					
    			$entry = mysql_query("INSERT INTO snaps VALUES('','$userid','$albumid','$serialid','$save_as','$name1','','$size1','$type1','$day')") or die(mysql_error());
    			
    			$avail 	= mysql_query("SELECT * FROM snaps WHERE albumid='$albumid' AND snapname='$name1' AND userid='$userid' ORDER BY albumid DESC");
    			$avail	= mysql_fetch_assoc($avail);
    			$sd	= $avail['snapid'];
    			$availability = mysql_query("INSERT INTO snapsavailability VALUES ('','$sd','$albumid','yes','no')");
    
    		}
                    else
                            header("location:upload.php?z=Couldnt upload file. Unsuitable file format. ");
    	        }
    
    	header("location:displayalbum.php?aid=$albumid");
    }
    
    PHP:
     
    Last edited: Jul 15, 2010
    cynical_tear, Jul 15, 2010 IP
  2. dbsuk

    dbsuk Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you tried to print $_FILES['snap1']['type']; when the error occurs?

    Is the output of $_FILES['snap1']['type']; one of your options?
     
    dbsuk, Jul 16, 2010 IP
  3. cynical_tear

    cynical_tear Peon

    Messages:
    107
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I have tried that and the output was JPEG format.


    Yes.. I'm using it to identify the type of file and then checking if the type is suitable for uploading or not. If it is not suitable format then it ll displays a message "Unsuitable file format"
     
    Last edited: Jul 16, 2010
    cynical_tear, Jul 16, 2010 IP
  4. dbsuk

    dbsuk Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It looks to me like it displays a message:

    Couldnt upload file. Unsuitable file format.

    When $name1 is not set?

    if($name1) 
    { 
    
    // code 
    
    }
    else
           header("location:upload.php?z=Couldnt upload file. Unsuitable file format. ");
    
    PHP:
    There is no else on the if($type1 == 'image/jpeg' || $type1 == ...... bit?

    Just a thought......

    ps. i have been up all night coding....so I could just be going nuts! Have a good day everyone! zzzz:cool:
     
    dbsuk, Jul 16, 2010 IP
  5. dbsuk

    dbsuk Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Also im thinking $abum_rows is always going to == 0 because its a typo:

    
    if($abum_rows == 0)
                {
    
    PHP:
     
    dbsuk, Jul 16, 2010 IP
  6. cynical_tear

    cynical_tear Peon

    Messages:
    107
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6

    No that is not the case... it will be zero only if user wants 2 create a new album.. if he wants to upload snaps in existing album then it will not be 0 but 1...
     
    cynical_tear, Jul 16, 2010 IP
  7. cynical_tear

    cynical_tear Peon

    Messages:
    107
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7

    can anyone help me???????????????????????????????????????
     
    cynical_tear, Jul 16, 2010 IP
  8. cynical_tear

    cynical_tear Peon

    Messages:
    107
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    the problem is solved.... This thread is closed now....
     
    cynical_tear, Jul 16, 2010 IP
  9. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #9
    DO NOT! rely on MIME-Type, use pathinfo() on the $_FILES['file']['name'] to retrieve the extension...
     
    danx10, Jul 16, 2010 IP