Small Image Upload Problem

Discussion in 'PHP' started by twodayslate, Sep 14, 2008.

  1. #1
    test: http://gorak.us/index1.php
    PHP
    <?php
    $dir = "uploads/";
    $file = basename( $_FILES['uploadedfile']['name']);
    $escape = str_replace(" ", "", $file);
    $file = $dir . $escape;
    
    if( 
    ($_FILES["uploadedfile"]["type"] == "image/gif" || $_FILES["uploadedfile"]["type"] == "image/jpg" || $_FILES["uploadedfile"]["type"] == "image/jpeg" || $_FILES["uploadedfile"]["type"] == "image/png" || $_FILES["uploadedfile"]["type"] == "image/pjpeg")//FILE TYPES
    && $_FILES["uploadedfile"]["size"] < 999999999 //File Size
    && !file_exists($file) )  //File does not already exist exists
    {
    	move_uploaded_file($_FILES["uploadedfile"]["tmp_name"], $file);
    	echo "<br /><a href=" . $file . ">" . $file . "</a>";
    }
    else 
    {
    	if(
    	!($_FILES["uploadedfile"]["type"] == "image/gif" || $_FILES["uploadedfile"]["type"] == "image/jpg" || $_FILES["uploadedfile"]["type"] == "image/jpeg" || $_FILES["uploadedfile"]["type"] == "image/png" || $_FILES["uploadedfile"]["type"] == "image/pjpeg")
    	)
    	{
    		echo "wrong format";
    	}
    	if(! ($_FILES["uploadedfile"]["size"] < 999999999) )
    	{
    		echo "too big";
    	}
    	if(file_exists($file))
    	{
    		echo "file exists";
    	}
    }
    Code (markup):
    It works, I think, but it does not let me upload large .jpgs. It give me wrong format though and not file is too big. Please feel free to test it out.
    Thanks! :thumbsup:

    upload_max_filesize	100M	100M
    Code (markup):
    When I try to upload my big jpgs the mime data says that it has no file type.
    post_max_size	8M	8M
    Code (markup):
    I don't see why this would give me a 'wrong format' error. I see why this would say it uploaded but really it didn't.


    //off topic: Links to any good begginner php mysql tutorials? Thanks
     
    twodayslate, Sep 14, 2008 IP
  2. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #2
    .jpgs file type is not support in your script
     
    php-lover, Sep 14, 2008 IP
  3. twodayslate

    twodayslate Well-Known Member

    Messages:
    541
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    130
    #3
    What is it then if it is not
    $_FILES["uploadedfile"]["type"] == "image/jpeg"
    Code (markup):
    I have been able to upload one jpg but I can't upload them all.
     
    twodayslate, Sep 15, 2008 IP
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    :) I though that you upload a new file type .jpgs

    try this mate

    $valid_img_type = array("image/gif","image/jpg","image/jpeg","image/png","image/pjpeg");
    
    if(!in_array($_FILES["uploadedfile"]["type"],$valid_img_type)){
    
       echo "wrong format";
    
    }//end if
    PHP:
     
    php-lover, Sep 15, 2008 IP