Results 1 to 10 of 10
  1. #1
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default [PHP] Upload help

    Every time I upload an image, even if I leave the field blank or upload the right file, I always get the error for incorrect file type :S
    PHP Code:
    elseif($_GET["act"] == "profilepic")
    {
            
    $max "10000000";
            
    $file $_FILES ["file"] ["name"];
            
    $type $_FILES ["file"] ["type"];
            
    $size $_FILES ["file"] ["size"];
            
    $tmpname $_FILES ["file"] ["tmp_name"];
            
    $info getimagesize $tmpname );
            
    $re1 '(image)';
        
        if(
    $file != "" || $size $max)
        {
                if (
    preg_match "/" $re1 "/is"image_type_to_mime_type $info [2] ) )) {
                    
                    
    $tempname $_FILES ["file"] ["tmp_name"];
                    
                    
    $file_spaces uniqid "img" ) . $_FILES ["file"] ["name"];
                    
    $name str_replace " ""_"$file_spaces );
                    
                    
    move_uploaded_file $tempname"/home/habbcr/public_html/djpanel/djpics/$name);
                    
                    
    mysql_query "UPDATE `users` SET `picture` = '$name' WHERE `username` = '$username'" );

                    
    notice("Profile Picture Updated!");
                    echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">Your new profile picture has now been uploaded. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");
                    
    endnotice();
                } else {
                    
    notice("Incorrect File Type");
                    echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">The file you tried uploading is <b>NOT</b> an image file. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");

                }
        }
        else 
        {
            
    notice("Error uploading file");
            echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">There was an error uploading your file. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");
        }

    So if the file is left blank, it is still getting past the first if :S

    Moved by Invent (Forum Moderator) from Designing & Development: Please post in the correct forum next time, thanks .
    Last edited by Invent; 24-08-2008 at 01:28 AM.

  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    It's getting by because if the size is 0 (no file was uploaded..) it is less then the $max..

  3. #3
    Join Date
    Nov 2007
    Posts
    1,253
    Tokens
    150

    Latest Awards:

    Default

    I think what you are looking for is to replace the

    ||

    with

    &&

    I dunno really, because I think || mean or rather than and.
    Last edited by Source; 19-08-2008 at 03:52 PM.


    www.fragme.co = a project.

  4. #4
    Join Date
    Aug 2005
    Location
    London
    Posts
    9,773
    Tokens
    146

    Latest Awards:

    Default

    Quote Originally Posted by Source View Post
    I think what you are looking for is to replace the

    ||

    with

    &&

    I dunno really, because I think || mean or rather than and.
    Yep, that should work as it's currently checking for if either one is true (The function for || ), the && is what you need to check if both match the criteria .

  5. #5
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    It's getting by because if the size is 0 (no file was uploaded..) it is less then the $max..
    Ah yes, but what about not letting me upload images if it meets the requirements?
    Quote Originally Posted by Source View Post
    I think what you are looking for is to replace the

    ||

    with

    &&

    I dunno really, because I think || mean or rather than and.
    || Should work.

  6. #6
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    || means or..

    So it's literally saying..

    If the file field is not blank or if the size is less then $max.

    it should be

    if the file filed is not blank AND (&&) if the size is less then $max

  7. #7
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Changed it to:
    PHP Code:
    elseif($_GET["act"] == "profilepic")
    {
            
    $max "10000000";
            
    $file $_FILES ["file"] ["name"];
            
    $type $_FILES ["file"] ["type"];
            
    $size $_FILES ["file"] ["size"];
            
    $tmpname $_FILES ["file"] ["tmp_name"];
            
    $info getimagesize $tmpname );
            
    $re1 '(image)';
        
        if(
    $file == "")
        {
            
    notice("Error uploading file");
            echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">You did not select a file to upload. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");    
        }
        elseif(
    $size $max)
        {
            
    notice("Error uploading file");
            echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">The file you selected is too big. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");    
        }
        else
        {
                if (
    preg_match "/" $re1 "/is"image_type_to_mime_type $info [2] ) )) {
                    
                    
    $tempname $_FILES ["file"] ["tmp_name"];
                    
                    
    $file_spaces uniqid "img" ) . $_FILES ["file"] ["name"];
                    
    $name str_replace " ""_"$file_spaces );
                    
                    
    move_uploaded_file $tempname"/home/habbcr/public_html/djpanel/djpics/$name);
                    
                    
    mysql_query "UPDATE `users` SET `picture` = '$name' WHERE `username` = '$username'" );

                    
    notice("Profile Picture Updated!");
                    echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">Your new profile picture has now been uploaded. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");
                    
    endnotice();
                } else {
                    
    notice("Incorrect File Type $tmpname");
                    echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">The file you tried uploading is <b>NOT</b> an image file. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");
                }
        }

    Now it can't get past:
    if($file == "")

    even if I have selected a file :S

  8. #8
    Join Date
    Oct 2006
    Location
    Peterborough, UK
    Posts
    3,855
    Tokens
    216

    Latest Awards:

    Default

    Quote Originally Posted by Jack120 View Post
    Changed it to:
    PHP Code:
    elseif($_GET["act"] == "profilepic")
    {
            
    $max "10000000";
            
    $file $_FILES ["file"] ["name"];
            
    $type $_FILES ["file"] ["type"];
            
    $size $_FILES ["file"] ["size"];
            
    $tmpname $_FILES ["file"] ["tmp_name"];
            
    $info getimagesize $tmpname );
            
    $re1 '(image)';
        
        if(
    $file == "")
        {
            
    notice("Error uploading file");
            echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">You did not select a file to upload. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");    
        }
        elseif(
    $size $max)
        {
            
    notice("Error uploading file");
            echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">The file you selected is too big. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");    
        }
        else
        {
                if (
    preg_match "/" $re1 "/is"image_type_to_mime_type $info [2] ) )) {
                    
                    
    $tempname $_FILES ["file"] ["tmp_name"];
                    
                    
    $file_spaces uniqid "img" ) . $_FILES ["file"] ["name"];
                    
    $name str_replace " ""_"$file_spaces );
                    
                    
    move_uploaded_file $tempname"/home/habbcr/public_html/djpanel/djpics/$name);
                    
                    
    mysql_query "UPDATE `users` SET `picture` = '$name' WHERE `username` = '$username'" );

                    
    notice("Profile Picture Updated!");
                    echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">Your new profile picture has now been uploaded. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");
                    
    endnotice();
                } else {
                    
    notice("Incorrect File Type $tmpname");
                    echo(
    "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"8;URL=?view=changedetails\">The file you tried uploading is <b>NOT</b> an image file. You are now being taken back to the \"change Your Details\" form<br /><br />If you'd prefer not to wait, please click <a href=\"?view=changedetails\">Here</a>");
                }
        }

    Now it can't get past:
    if($file == "")

    even if I have selected a file :S
    Sorry are you stupid or something, Caleb gave you (from what i can see after i skimmed it) the correct answer, use && instead of ||.


    visit my internet web site on the internet
    http://dong.engineer/
    it is just videos by bill wurtz videos you have been warned

  9. #9
    Join Date
    May 2006
    Location
    Hull
    Posts
    7,701
    Tokens
    2,430
    Habbo
    Moh

    Latest Awards:

    Default

    Quote Originally Posted by Jewish Bear View Post
    Sorry are you stupid or something, Caleb gave you (from what i can see after i skimmed it) the correct answer, use && instead of ||.
    When I changed it to && it still didnt work.

    I'm surprised no one told me to look at the form, I noticed I didn't add enctype="multipart/form-data" to the form :eusa_wall

  10. #10
    Join Date
    May 2008
    Posts
    605
    Tokens
    0

    Default

    Quote Originally Posted by Jack120 View Post
    When I changed it to && it still didnt work.

    I'm surprised no one told me to look at the form, I noticed I didn't add enctype="multipart/form-data" to the form :eusa_wall
    I no no see form.

Posting Permissions

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