SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 55
  1. #1
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using getimagesize with an ARRAY? Need help please.

    I used this getimagesize on anothr page on my site and it works fine. On the first page I used it on the user can upload only one image. I am trying to use it on another page now. On this page of the site it is a profile page. The user can upload up to six pictures when they first create thier profile. If the user doesn't upload all six photos and only uploads only three when they then choose to edit thier profile the three photos they previously uploaded are lined side by side with the other three not uploaded file inputs under it. I think the getimagesize is not working because it is more than one image. With the new pictures the code pulls the original pictures the user uploaded ($_POST['OldImages']) I think this is why I might be getting an error. I am not sure. I did use rtrim for an ARRAY but it doesn't seemt o be working. I will include my code and my error. when I try to upload a pic I get an error of:
    Warning: getimagesize: Unable to open 'Array' for reading. in c:\apache\htdocs\ds\edit.php on line 8

    Here is line 8:
    $imgSize = getimagesize(rtrim($_FILES['images']['tmp_name']));

    Then if I click the back button on my browser the pic was uploaded but not passed thru making sure it is only .gif or .jpg or that the max width and height is 640! Any help would be greatly appreciated.

    Here is the whole bunch of code:
    PHP Code:
    if(isset($_POST[s1]))
    {

    $imgSize getimagesize(rtrim($_FILES['images']['tmp_name']));

            if(
    $imgSize === false)
            {
                    
    //not an image
                    
    $error "<b>Your banner must be an image</b>";
            }
            else if (
    $imgSize[0] = 640 || $imgSize[1] = 640)
            {
                    
    $error "<b>For best results your image should be either 640 wide by 480 high<br>
                    or 480 wide by 640 high, no larger!</b>"
    ;
            }
            else if(
    $imgSize[2] != && $imgSize[2] != 2)
            {
                    
    $error "<b>You can upload only .gif & .jpg image files!</b>";
            }




            if(!empty(
    $_FILES['images']['name'][0]))
            {
                    while(list(
    $key,$value) = each($_FILES['images']['name']))
                    {
                            if(!empty(
    $value))
                            {
                                    
    $NewImageName $t."_offer_".$value;
                                    
    copy($_FILES['images']['tmp_name'][$key], "ds_images/".$NewImageName);

                                    
    $MyImages[] = $NewImageName;
                            }
                    }

                    if(!empty(
    $MyImages))
                    {
                            
    $ImageStr implode("|"$MyImages);

                            if(!empty(
    $_POST['OldImages']))
                            {
                                    
    $ImageStr $ImageStr."|".$_POST['OldImages'];
                            }
                    }

            }
            else
            {
                    
    $ImageStr $_POST['OldImages'];
            }

            
    $catInfo explode("|"$_POST[SelectCategory]);
            
    $CategoryID $catInfo[0];
            
    $SubcategoryID $catInfo[1];
            
    $SubcategoryName $catInfo[2]; 

  2. #2
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $imgSize = getimagesize(rtrim($_FILES['images']['tmp_name']));


    Okay rtrim is completely inappropriate here.

    You need to figure out the imagesize for each image anyway. Where is your loop? You need something like...

    PHP Code:
    foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
      
    $imgSize getimagesize($tmpImageName);
      
    // Test for dimensions and filetype...


  3. #3
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    This:
    Quote Originally Posted by netfreakz
    PHP Code:
     else if ($imgSize[0] = 640 || $imgSize[1] = 640
    Should be:
    PHP Code:
    else if ($imgSize[0] <= 640 || $imgSize[1] <= 640
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  4. #4
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ZareMedia
    $imgSize = getimagesize(rtrim($_FILES['images']['tmp_name']));


    Okay rtrim is completely inappropriate here.

    You need to figure out the imagesize for each image anyway. Where is your loop? You need something like...

    PHP Code:
    foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
      
    $imgSize getimagesize($tmpImageName);
      
    // Test for dimensions and filetype...


    ok i put your code into my script replacing the original getimagesize i post and i got these errors...

    Warning: getimagesize: Unable to open 'none' for reading. in c:\apache\htdocs\ds\edit.php on line 9

    Warning: getimagesize: Unable to open 'none' for reading. in c:\apache\htdocs\ds\edit.php on line 9

  5. #5
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth
    This:
    Should be:
    PHP Code:
    else if ($imgSize[0] <= 640 || $imgSize[1] <= 640
    Thank you for pointing that out to me logic_earth

  6. #6
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok the script is getting the new image name if a new image is being uploaded but also posting the old images the user might have uploaded previously. Wouldn't i also have to pass the $_POST[OldImages] thru getimagesize too for the script to work on my page? If so would I be able to configure getimagesize like this:
    foreach($_FILES['images']['tmp_name'], $_POST['OldImages'] as $tmpImageName) {
    $imgSize = getimagesize($tmpImageName);
    // Test for dimensions and filetype...
    }

  7. #7
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does anyone have any idea what I am doing wrong I still have no luck....

  8. #8
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
      if (
    file_exists($tmpImageName)) {
        
    $imgSize getimagesize($tmpImageName);
        
    // Test for dimensions and filetype...
      
    }


  9. #9
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ZareMedia
    PHP Code:
    foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
      if (
    file_exists($tmpImageName)) {
        
    $imgSize getimagesize($tmpImageName);
        
    // Test for dimensions and filetype...
      
    }

    I just tried what you suggested i get no errors but i can upload any image type instead of only gif and jpg and it doesnt limit the size to 640 width and 640 height. Thank you for trying to help me.

  10. #10
    SitePoint Addict
    Join Date
    Jul 2006
    Location
    Kansas City, MO
    Posts
    280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Paste your code. Your sloppy coding has numerous problems up above, so I won't be surprised to point out a handful of more errors.

  11. #11
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ZareMedia
    Paste your code. Your sloppy coding has numerous problems up above, so I won't be surprised to point out a handful of more errors.
    Ok thank you my code is below...

    CODE:
    PHP Code:
    <?
    require_once("conn.php");
    require_once(
    "includes.php");

    if(isset(
    $_POST[s1]))
    {

    foreach(
    $_FILES['images']['tmp_name'] as $tmpImageName) {
      if (
    file_exists($tmpImageName)) {
        
    $imgSize getimagesize($tmpImageName);
        
    // Test for dimensions and filetype...
      
    }
    }

            if(
    $imgSize === false)
            {
                    
    //not an image
                    
    $error "<b>Your picture must be an image</b>";
            }
            else if (
    $imgSize[0] <= 640 || $imgSize[1] <= 640)

            {
                    
    $error "<b>For best results your image should be either 640 wide by 480 high<br>
                    or 480 wide by 640 high, no larger!</b>"
    ;
            }
            else if(
    $imgSize[2] != && $imgSize[2] != 2)
            {
                    
    $error "<b>You can upload only .gif & .jpg image files!</b>";
            }


            if(!empty(
    $_FILES['images']['name'][0]))
            {
                    while(list(
    $key,$value) = each($_FILES['images']['name']))
                    {
                            if(!empty(
    $value))
                            {
                                    
    $NewImageName $t."_offer_".$value;
                                    
    copy($_FILES['images']['tmp_name'][$key], "ds_images/".$NewImageName);

                                    
    $MyImages[] = $NewImageName;
                            }
                    }

                    if(!empty(
    $MyImages))
                    {
                            
    $ImageStr implode("|"$MyImages);

                            if(!empty(
    $_POST[OldImages]))
                            {
                                    
    $ImageStr $ImageStr."|".$_POST[OldImages];
                            }
                    }

            }
            else
            {
                    
    $ImageStr $_POST[OldImages];
            }

            
    $catInfo explode("|"$_POST[SelectCategory]);
            
    $CategoryID $catInfo[0];
            
    $SubcategoryID $catInfo[1];
            
    $SubcategoryName $catInfo[2];

            
    $q1 "UPDATE ds_profile set

  12. #12
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php

    require_once("conn.php");
    require_once(
    "includes.php");

    $acceptedImages = array(IMG_GIFIMG_JPGIMG_PNG);

    if(isset(
    $_POST[s1])) {

        foreach(
    $_FILES['images']['tmp_name'] as $tmpImageName) {
            if (
    file_exists($tmpImageName)) {
                
    $imgSize getimagesize($tmpImageName);
                

                if (
    $imgSize === false) {
                    exit(
    '<b>Your picture must be an image.</b>');
                } else if (
    $imgSize[0] > 640 || $imgSize[1] > 640) {
                    exit(
    '<b>Your image can not be larger then 640 by 640.</b>');
                } else if (!
    in_array($imgSize[2], $acceptedImages)) {
                    exit(
    '<b>You can only upload GIF, JPEG, and PNGs files.</b>');
                }
            }
        }

        
    $l count($_FILES['images']['tmp_name']);
        for (
    $i 0$i $l$i++) {

            
    // Okay...I'm really confused at what you are exactly doing... but to
            // Process the uploaded images you would do it here...in this for loop.
            // That is if i assume what you want but like I said very confusing.

        
    }
    }
    Okay...I'm really confused at what you are exactly doing...but to Process the uploaded images you would do it there in that for loop. That is if i assume what you want but like I said very confusing.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  13. #13
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth
    PHP Code:
    <?php

    require_once("conn.php");
    require_once(
    "includes.php");

    $acceptedImages = array(IMG_GIFIMG_JPGIMG_PNG);

    if(isset(
    $_POST[s1])) {

        foreach(
    $_FILES['images']['tmp_name'] as $tmpImageName) {
            if (
    file_exists($tmpImageName)) {
                
    $imgSize getimagesize($tmpImageName);
                

                if (
    $imgSize === false) {
                    exit(
    '<b>Your picture must be an image.</b>');
                } else if (
    $imgSize[0] > 640 || $imgSize[1] > 640) {
                    exit(
    '<b>Your image can not be larger then 640 by 640.</b>');
                } else if (!
    in_array($imgSize[2], $acceptedImages)) {
                    exit(
    '<b>You can only upload GIF, JPEG, and PNGs files.</b>');
                }
            }
        }

        
    $l count($_FILES['images']['tmp_name']);
        for (
    $i 0$i $l$i++) {

            
    // Okay...I'm really confused at what you are exactly doing... but to
            // Process the uploaded images you would do it here...in this for loop.
            // That is if i assume what you want but like I said very confusing.

        
    }
    }
    Okay...I'm really confused at what you are exactly doing...but to Process the uploaded images you would do it there in that for loop. That is if i assume what you want but like I said very confusing.
    No luck logic_earth I have been trying to figure this out all day. If you did not already read this entire post it describes what is going on with this page and with what i am trying to do. I tried your code and it didnt work for me. Thanks for your help. Vin

  14. #14
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Well i'll try it on my end and server if it work or requires changing i'll post the results.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  15. #15
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth
    Well i'll try it on my end and server if it work or requires changing i'll post the results.
    would you like for me to send you my docs for it? I do appreciate you helping me.

  16. #16
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    netfreakz, it looks like you're again back to one of the problems we solved last week, specifically that IMG_GIF, IMG_JPG, and now IMG_PNG are not defined. Either define these (with define) or replace them with the numerical values noted in the PHP manual for getimagesize for the image types you want to allow.
    PHP questions? RTFM
    MySQL questions? RTFM

  17. #17
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kromey
    netfreakz, it looks like you're again back to one of the problems we solved last week, specifically that IMG_GIF, IMG_JPG, and now IMG_PNG are not defined. Either define these (with define) or replace them with the numerical values noted in the PHP manual for getimagesize for the image types you want to allow.
    Kromey i was hoping to see you.. Thank god....
    Ok The script i will post here take a look I will have to explain what it is doing so you understand. Other people were getting confused. Please give me a few minutes to prepare this new post for your to read.

  18. #18
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok a user can go to my website and register, Once they register it takes them to a control panel which gives them an option to set a profile where they can type stuff about things and also upload up to six images. If the first time they make thier profile they only upload 3 images in the future if they decide to edit thier profile they will have the option to add another three photos yet the original three the uploaded when they first made thier profile will automatically be there with the delete option under each pic. If the user does not delete the orig pics that is where the part of this script says

    PHP Code:
                           if(!empty($_POST[OldImages]))
                            {
                                    
    $ImageStr $ImageStr."|".$_POST[OldImages];
                            }
                    }

            }
            else
            {
                    
    $ImageStr $_POST[OldImages];
            } 
    Now I have been trying to use getimagesize to work but for it to work properly not only do i have to validate the new images the user is uploading but also the old images they originally uploaded. Here is the full script. If you can help me this is the last problem i am having that i can not fix by myself and i will be very grateful...

    Here is the code:
    PHP Code:
    if(isset($_POST[s1]))
    {

    foreach(
    $_FILES['images']['tmp_name'] as $tmpImageName) {
      if (
    file_exists($tmpImageName)) {
        
    $imgSize getimagesize($tmpImageName);
        
    // Test for dimensions and filetype...
      
    }
    }

            if(
    $imgSize === false)
            {
                    
    //not an image
                    
    $error "<b>Your banner must be an image</b>";
            }
            else if (
    $imgSize[0] <= 640 || $imgSize[1] <= 640)

            {
                    
    $error "<b>For best results your image should be either 640 wide by 480 high<br>
                    or 480 wide by 640 high, no larger!</b>"
    ;
            }
            else if(
    $imgSize[2] != && $imgSize[2] != 2)
            {
                    
    $error "<b>You can upload only .gif & .jpg image files!</b>";
            }


            if(!empty(
    $_FILES['images']['name'][0]))
            {
                    while(list(
    $key,$value) = each($_FILES['images']['name']))
                    {
                            if(!empty(
    $value))
                            {
                                    
    $NewImageName $t."_offer_".$value;
                                    
    copy($_FILES['images']['tmp_name'][$key], "re_images/".$NewImageName);

                                    
    $MyImages[] = $NewImageName;
                            }
                    }

                    if(!empty(
    $MyImages))
                    {
                            
    $ImageStr implode("|"$MyImages);

                            if(!empty(
    $_POST[OldImages]))
                            {
                                    
    $ImageStr $ImageStr."|".$_POST[OldImages];
                            }
                    }

            }
            else
            {
                    
    $ImageStr $_POST[OldImages];
            }

            
    $catInfo explode("|"$_POST[SelectCategory]);
            
    $CategoryID $catInfo[0];
            
    $SubcategoryID $catInfo[1];
            
    $SubcategoryName $catInfo[2];

            
    $q1 "UPDATE ds_listings set
                                            CategoryID = '
    $CategoryID',
                                            SubcategoryID = '
    $SubcategoryID',
                                            SubcategoryName = '
    $SubcategoryName',
                                            Weight = '
    $_POST[Weight]',
                                            city = '
    $_POST[city]',
                                            state = '
    $_POST[state]',
                                            oneliner = '
    $_POST[oneliner]',
                                            greeting = '
    $_POST[greeting]',
                                            description1 = '
    $_POST[description1]',
                                            Price = '
    $_POST[Price]',
                                            incall = '
    $_POST[incall]',
                                            description2 = '
    $_POST[description2]',
                                            Height = '
    $_POST[Height]',
                                            BodyType = '
    $_POST[BodyType]',
                                            Liner = '
    $_POST[Liner]',
                                            HairColor = '
    $_POST[HairColor]',
                                            EyeColor = '
    $_POST[EyeColor]',
                                            Ethnicity = '
    $_POST[Ethnicity]',
                                            UserAge = '
    $_POST[UserAge]',
                                            AttentionColor = '
    $_POST[AttentionColor]',
                                            DetailsColor = '
    $_POST[DetailsColor]',
                                            Preference = '
    $_POST[Preference]',
                                            Site = '
    $_POST[Site]',
                                            Website = '
    $_POST[Website]',
                                            Visit = '
    $_POST[Visit]',
                                            FromMonth = '
    $_POST[FromMonth]',
                                            FromDay = '
    $_POST[FromDay]',
                                            ToMonth = '
    $_POST[ToMonth]',
                                            ToDay = '
    $_POST[ToDay]',
                                            image = '
    $ImageStr'

                                            where ListingID = '
    $_GET[id]' and AgentID = '$_SESSION[AgentID]' ";

            
    mysql_query($q1);

            if(
    mysql_error())
            {
                    echo 
    mysql_error();
            }
            else
            {

            
    header("location:info.php?id=$_GET[id]");
            exit();
    }


  19. #19
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, first thing I see right off the bat is something we went over last night, specifically that arrays indexed non-numerically (i.e. associative arrays) use strings as keys; thus, things like
    PHP Code:
    if(!empty($_POST[OldImages])) 
    should instead look like
    PHP Code:
    if(!empty($_POST['OldImages'])) 
    If you turn error reporting up in the same manner that I suggested last night, you'll see a whole slew of "Unknown offset" warnings again.

    Next, take a look at the code that Logic_Earth posted above, and notice that in his code image validation happens inside the foreach loop. That's where it needs to be, otherwise you're only validating the last image (if even that).

    Make those changes and repost your code along with any/all errors and we'll see where we need to go from there.
    PHP questions? RTFM
    MySQL questions? RTFM

  20. #20
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    would this work?
    PHP Code:
    foreach($_FILES['images']['tmp_name'], $_POST['OldImages'] as $tmpImageName) {
    $imgSize getimagesize($tmpImageName);
    // Test for dimensions and filetype...


  21. #21
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kromey
    Okay, first thing I see right off the bat is something we went over last night, specifically that arrays indexed non-numerically (i.e. associative arrays) use strings as keys; thus, things like
    PHP Code:
    if(!empty($_POST[OldImages])) 
    should instead look like
    PHP Code:
    if(!empty($_POST['OldImages'])) 
    If you turn error reporting up in the same manner that I suggested last night, you'll see a whole slew of "Unknown offset" warnings again.

    Next, take a look at the code that Logic_Earth posted above, and notice that in his code image validation happens inside the foreach loop. That's where it needs to be, otherwise you're only validating the last image (if even that).

    Make those changes and repost your code along with any/all errors and we'll see where we need to go from there.
    I tried to use his code and when i tried it it deleted all the info in the datbase for that users profile.. I will make the ''changes now

  22. #22
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should, yes, provided that you replace the comment that says "Test for dimensions and filetype..." with the code that does such. Comments are not magical pieces of code, they are aides for anyone looking at the code.
    PHP questions? RTFM
    MySQL questions? RTFM

  23. #23
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh ok

  24. #24
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by netfreakz
    I tried to use his code and when i tried it it deleted all the info in the datbase for that users profile.. I will make the ''changes now
    Are you sure? There's nothing in his code that would touch the database at all.
    PHP questions? RTFM
    MySQL questions? RTFM

  25. #25
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kromey
    Are you sure? There's nothing in his code that would touch the database at all.
    I will put it like i had it when that happened maybe i put it together wrong
    i will post it in a minute


Bookmarks

Posting Permissions

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