SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 35

Thread: Getimagesize loop only checks first image?

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

    Getimagesize loop only checks first image?

    Getimagesize with loop
    it only checks the first image.... here is the code. I need it to check the remaining images...

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

    if(isset(
    $_POST['s1']))
    {
    //echo gettype($_FILES['images']['tmp_name']) . "<br>";
    //print_r($_FILES['images']['tmp_name']);


        
    foreach($_FILES['images']['tmp_name'] as $tmpImageName)
        {
    //    $l = count($_FILES['images']['tmp_name']);
    //    for ($i = 0; $i < $l; $i++)
    //    {
            
    if (file_exists($tmpImageName))
            {
            
    $imgSize getimagesize(rtrim($tmpImageName));
            if (
    $imgSize === false)
            {
                    
    $error "<b>File is not an image.</b>";
            }
            else if (
    $imgSize[0] > 640 || $imgSize[1] > 640)
            {
            
    print_r($imgSize); //verify the dimensions
            
    $error "<b>Your image can not be larger then 640 by 640.</b>";
            }
            else if (
    $imgSize[2] != && $imgSize[2] != 2)
            {
            
    $error "<b>You can only upload GIF, JPEG files.</b>";
            }
            else
            {
            if(!empty(
    $_FILES['images']['name'][0]))
            {
                    while(list(
    $key,$value) = each($_FILES['images']['name']))
                    {
                            if(!empty(
    $value))
                            {
                                    
    $NewImageName $AgentID.$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 Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If I rember correctly the $_FILES['images']['tmp_name'] is a string and not an array. I think you'll have to iterate over $_FILES array.

    Use print_r() to see how your $_FILES array looks like:
    PHP Code:
    echo '<pre>';
    print_r($_FILES);
    echo 
    '</pre>'
    Post the print out back here if you need more help.

    -H

  3. #3
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Helge
    If I rember correctly the $_FILES['images']['tmp_name'] is a string and not an array. I think you'll have to iterate over $_FILES array.

    Use print_r() to see how your $_FILES array looks like:
    PHP Code:
    echo '<pre>';
    print_r($_FILES);
    echo 
    '</pre>'
    Post the print out back here if you need more help.

    -H
    Sorry where should i include that in my script?

  4. #4
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is what it printed out:
    Array
    (
    [images] => Array
    (
    [name] => Array
    (
    [0] => Tracy___Kevin.JPG
    [1] => Tracy_06.JPG
    [2] => The_Family_06.JPG
    [3] => MELISSA__SKYLAR___JO.JPG
    [4] => Dave___Skylar.JPG
    [5] =>
    )

    [type] => Array
    (
    [0] => image/pjpeg
    [1] => image/pjpeg
    [2] => image/pjpeg
    [3] => image/pjpeg
    [4] => image/pjpeg
    [5] => application/octet-stream
    )

    [tmp_name] => Array
    (
    [0] => C:\WINDOWS\php87E.tmp
    [1] => C:\WINDOWS\php87F.tmp
    [2] => C:\WINDOWS\php880.tmp
    [3] => C:\WINDOWS\php881.tmp
    [4] => C:\WINDOWS\php882.tmp
    [5] => none
    )

    [size] => Array
    (
    [0] => 346285
    [1] => 306872
    [2] => 411569
    [3] => 417211
    [4] => 411024
    [5] => 0
    )

    )

    )

    Array ( [0] => 1536 [1] => 1024 [2] => 2 [3] => width="1536" height="1024" [bits] => 8 [channels] => 3 ) Array ( [0] => 1536 [1] => 1024 [2] => 2 [3] => width="1536" height="1024" [bits] => 8 [channels] => 3 ) Array ( [0] => 1536 [1] => 1024 [2] => 2 [3] => width="1536" height="1024" [bits] => 8 [channels] => 3 ) Array ( [0] => 1536 [1] => 1024 [2] => 2 [3] => width="1536" height="1024" [bits] => 8 [channels] => 3 ) Array ( [0] => 1536 [1] => 1024 [2] => 2 [3] => width="1536" height="1024" [bits] => 8 [channels] => 3 )

  5. #5
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, I've never seen the $_FILES array like that, but that doesn't really matter. Your foreach() is corrent the way it is.

    I don't understand the logic in that script, especially the while() loop. That one will iterate over every name/file and copy the file for every lap the foreach() loop takes. To me it seems that you'll end up with a lot of files.

    If you explain what you want it to do I might come up with a suggestion.

  6. #6
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cleaned up version.
    PHP Code:
    <? 
    require_once("conn.php"); 
    require_once(
    "includes.php"); 

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




        foreach(
    $_FILES['images']['tmp_name'] as $tmpImageName
        { 
    //    $l = count($_FILES['images']['tmp_name']); <---counter but doesnt 
    //    for ($i = 0; $i < $l; $i++)                          <  really affect the way the 
    //    {                                                             <script runs...
            
    if (file_exists($tmpImageName)) 
            { 
            
    $imgSize getimagesize(rtrim($tmpImageName)); 
            if (
    $imgSize === false
            { 
                    
    $error "<b>File is not an image.</b>"
            } 
            else if (
    $imgSize[0] > 640 || $imgSize[1] > 640
            { 
            
    print_r($imgSize); //verify the dimensions 
            
    $error "<b>Your image can not be larger then 640 by 640.</b>"
            } 
            else if (
    $imgSize[2] != && $imgSize[2] != 2
            { 
            
    $error "<b>You can only upload GIF, JPEG files.</b>"
            } 
            else 
            { 
            if(!empty(
    $_FILES['images']['name'][0])) 
            { 
                    while(list(
    $key,$value) = each($_FILES['images']['name'])) 
                    { 
                            if(!empty(
    $value)) 
                            { 
                                    
    $NewImageName $AgentID.$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];
    users go to thier user c/p and the have the option to set up a profile. When they first set up thier profile they have the option to upload up to 6 pics. I am trying to validate all 6 file inputs for the six pics with the variables in the script. but the loop doent seem to be working correctly, unless i need a counter? I am newb and i am lucky i got this far! I am pretty much stuck right now. I have had other people help me but havent been anle to get it the way i need it.. is there any other info you would need in order to try to help me? I do appreciate it much.. thank you.

  7. #7
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi.

    Try something like this. I've added some comments where my code differs from yours:
    PHP Code:
    $MyImages = array(); // Holds the names of the successful uploaded images
    $errors = array(); // Holds the errors for all of the images.
    foreach($_FILES['images']['tmp_name'] as $i => $tmpImageName) {
        
        
    // Grabs the original filename
        
    $imageName $_FILES['images']['name'][$i];
        
        if (
    file_exists($tmpImageName)) {
            
    $imgSize getimagesize(trim($tmpImageName));

            if (
    $imgSize === false) {
                
    $errors[$i] = "<b>File #$i ($imageName) is not an image.</b>";
            } elseif (
    $imgSize[0] > 640 || $imgSize[1] > 640) {
                
    $errors[$i] = "<b>Image #$i ($imageName) is to big. It can't be larger then 640 by 640.</b>";
            } elseif (
    $imgSize[2] != && $imgSize[2] != 2) {
                
    $errors[$i] = "<b>Image #$i ($imageName) is of incorrect image type. You can only upload GIF, JPEG files.</b>";
            } else {
                
    // Where you want to save the uploaded images.
                
    $uploadDir 'ds_images/';
                
                
    // Add the AgentID to the original filename
                
    $fileName $AgentID.$imageName;
                
                
    // Tries to move the uploaded file from the temporary dir to the spesified dir.
                // Using the move_upload_file() function instead of copy() because it's made for
                // this purpose.
                
    if(move_uploaded_file($fileName$uploadDir)) {
                    
    $MyImages[] = $fileName;
                } else {
                    
    $errors[$i] = "<b>Image #$i ($imageName) could not be saved.</b>";
                }
            }
        } else {
            
    $errors[$i] = "<b>The temporary file for image #$i ($imageName) could not be located.</b>";
        }
    }

    // Echo out any errormessages. The errors are kept in an array so it's
    // possible to echo them out after all the files have been iteratet over.
    // That gives you more flexibility where to echo them out.
    if(!empty($errors)) {
        echo 
    '<strong>The following errror(s) occured:</strong><ul>';
        foreach(
    $errors AS $error) {
            echo 
    "<li>$error</li>";
        }
        echo 
    '</ul>';
    }

    // Check if any images were uploaded
    if(!empty($MyImages)) {
        
    $ImageStr implode('|'$MyImages);
        if(!empty(
    $_POST['OldImages'])) {
            
    $ImageStr .= '|' $_POST['OldImages'];
        }
    // No images were uploaded
    } else {
        
    $ImageStr $_POST['OldImages'];

    I've not tested this code so it might be buggy.

    See move_uploaded_file().

    -H

  8. #8
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for helping me.

    line 27:
    $fileName = $AgentID.$imageName;

    i ran it and got this:
    Parse error: parse error in c:\apache\htdocs\floridafinecars\edit.php on line 27

  9. #9
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try:
    PHP Code:
    $fileName "$AgentID$imageName"
    What do the $AgentID look like?

  10. #10
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i ran the same error... should i use ' '

  11. #11
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope that didn't work

  12. #12
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to echo the variables to see what they looks like:
    PHP Code:
     echo "AgentID: $AgentID<br>";
    echo 
    "imageName: $imageName<br>";

    $fileName "$AgentID$imageName"

  13. #13
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Parse error: parse error in c:\apache\htdocs\floridafinecars\edit.php on line 68 now i get this parse error

    line 68:
    else

  14. #14
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    "My" code do not have 68 lines so you need to post the lines before and after line 68.

  15. #15
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    require_once("conn.php");
    require_once(
    "includes.php");
    if(isset(
    $_POST['s1']))
    {
    $MyImages = array(); // Holds the names of the successful uploaded images
    $errors = array(); // Holds the errors for all of the images.
    foreach($_FILES['images']['tmp_name'] as $i => $tmpImageName) {

        
    // Grabs the original filename
        
    $imageName $_FILES['images']['name'][$i];

        if (
    file_exists($tmpImageName)) {
            
    $imgSize getimagesize(trim($tmpImageName));

            if (
    $imgSize === false) {
                
    $errors[$i] = "<b>File #$i ($imageName) is not an image.</b>";
            } elseif (
    $imgSize[0] > 640 || $imgSize[1] > 640) {
                
    $errors[$i] = "<b>Image #$i ($imageName) is to big. It can't be larger then 640 by 640.</b>";
            } elseif (
    $imgSize[2] != && $imgSize[2] != 2) {
                
    $errors[$i] = "<b>Image #$i ($imageName) is of incorrect image type. You can only upload GIF, JPEG files.</b>";
            } else {
                
    // Where you want to save the uploaded images.
                
    $uploadDir 'ds_images/';

                
    // Add the AgentID to the original filename
    echo "AgentID: $AgentID<br>";
    echo 
    "imageName: $imageName<br>";

    $fileName "$AgentID$imageName";

                
    // Tries to move the uploaded file from the temporary dir to the spesified dir.
                // Using the move_upload_file() function instead of copy() because it's made for
                // this purpose.
                
    if(move_uploaded_file($fileName$uploadDir)) {
                    
    $MyImages[] = $fileName;
                } else {
                    
    $errors[$i] = "<b>Image #$i ($imageName) could not be saved.</b>";
                }
            }
        } else {
            
    $errors[$i] = "<b>The temporary file for image #$i ($imageName) could not be located.</b>";
        }
    }

    // Echo out any errormessages. The errors are kept in an array so it's
    // possible to echo them out after all the files have been iteratet over.
    // That gives you more flexibility where to echo them out.
    if(!empty($errors)) {
        echo 
    '<strong>The following errror(s) occured:</strong><ul>';
        foreach(
    $errors AS $error) {
            echo 
    "<li>$error</li>";
        }
        echo 
    '</ul>';
    }

    // Check if any images were uploaded
    if(!empty($MyImages)) {
        
    $ImageStr implode('|'$MyImages);
        if(!empty(
    $_POST['OldImages'])) {
            
    $ImageStr .= '|' $_POST['OldImages'];
        }
    // No images were uploaded
    } else {
        
    $ImageStr $_POST['OldImages'];
    }

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

            
    $catInfo explode("|"$_POST[SelectCategory]);
            
    $CategoryID $catInfo[0];
            
    $SubcategoryID $catInfo[1];
            
    $SubcategoryName $catInfo[2];
            
    $q1 "UPDATE discreet_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();
                   }
                }

             }
          }
      }

  16. #16
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at line 68. What if-clause do that else correspond to. You can't just take my code and copy it into yours without checking that the flow is correct.

    I suggest that you "delete" everything after line 67 and get the upload part working first. When that is working fine you start dealing with the database stuff. Or?

  17. #17
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok I will try it now
    ty

  18. #18
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you i got it working but for some reason it wont save any files. I get this error:
    The following errror(s) occured:
    Image #0 (new do.jpg) could not be saved.

    Warning: Cannot add header information - headers already sent by (output started at c:\apache\htdocs\floridafinecars\edit.php:55) in c:\apache\htdocs\floridafinecars\edit.php on line 122

  19. #19
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try to set the $uploadDir = 'ds_images/'; to the absolut path, like:
    Code:
    c:\apache\htdocs\floridafinecars\upload\
    if that is the correct path.

    About the "headers already sent" error is because you echo out error messages and later on in your script (after the db update) you try forward to another page ( header(Location: ....); ). You cannot sent anything to the browser before all the headers are sent.

  20. #20
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did what you suggested but i have no such luck. I am ready to shoot myself because of this damn problem...lol well ty for all the help.

  21. #21
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i know what the part of the problem is... typo we both overlooked!!
    was:
    if(move_uploaded_file($fileName, $uploadDir)

    Should be:
    if(!move_uploaded_file($fileName, $uploadDir)

  22. #22
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, I might have read the manual wrong. Replace this the actual file saving with this:
    PHP Code:
                // Where you want to save the uploaded images.
                
    $uploadDir 'c:' .DIRECTORY_SEPARATOR'apache' .DIRECTORY_SEPARATOR'htdocs' .DIRECTORY_SEPARATOR'floridafinecars' .DIRECTORY_SEPARATOR'upload'

                
    // Add the AgentID to the original filename
                
    $fileName "$AgentID$imageName";
                
    $newLocation DIRECTORY_SEPARATOR.$fileName;

                
    // Tries to move the uploaded file from the temporary dir to the spesified dir.
                // Using the move_upload_file() function instead of copy() because it's made for
                // this purpose.
                
    if(move_uploaded_file($tmpImageName$newLocation)) {
                    
    $MyImages[] = $fileName;
                } else {
                    
    $errors[$i] = "<b>Image #$i ($imageName) could not be saved.</b>";
                } 
    Also make sure that the directory actually exists.

  23. #23
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it working but now i need to tweak it to match the rest of my site. It is odd the pictures appear on the site but when i look in the folder they arent there? WHY????
    lol, also how can I output all my errors using $error = "<b>blah blah blah</b>";
    and out put the errors like <?=$error?> to my html page?

  24. #24
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no matter what image it can not be saved it says..

    The following errror(s) occured:
    The temporary file for image #1 () could not be located.
    The temporary file for image #2 () could not be located.
    The temporary file for image #3 () could not be located.
    The temporary file for image #4 () could not be located.

  25. #25
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by netfreakz
    i know what the part of the problem is... typo we both overlooked!!
    PHP Code:
    //was:
    if(move_uploaded_file($fileName$uploadDir)
    //Should be:
    if(!move_uploaded_file($fileName$uploadDir
    I don't think that is a typo...
    Quote Originally Posted by netfreakz
    The following errror(s) occured:
    The temporary file for image #1 () could not be located.
    The temporary file for image #2 () could not be located.
    The temporary file for image #3 () could not be located.
    The temporary file for image #4 () could not be located.
    Try to remove the if(file_exists($tmpImageName)) clause, cause you'll get a check when using the move_uploaded_files() anyway. That gives you this code:
    PHP Code:
    <?
    require_once("conn.php");
    require_once(
    "includes.php");
    if(isset(
    $_POST['s1']))
    {
    $MyImages = array(); // Holds the names of the successful uploaded images
    $errors = array(); // Holds the errors for all of the images.
    foreach($_FILES['images']['tmp_name'] as $i => $tmpImageName) {

        
    // Grabs the original filename
        
    $imageName $_FILES['images']['name'][$i];

        
    $imgSize getimagesize(trim($tmpImageName));

        if (
    $imgSize === false) {
            
    $errors[$i] = "<b>File #$i ($imageName) is not an image.</b>";
        } elseif (
    $imgSize[0] > 640 || $imgSize[1] > 640) {
            
    $errors[$i] = "<b>Image #$i ($imageName) is to big. It can't be larger then 640 by 640.</b>";
        } elseif (
    $imgSize[2] != && $imgSize[2] != 2) {
            
    $errors[$i] = "<b>Image #$i ($imageName) is of incorrect image type. You can only upload GIF, JPEG files.</b>";
        } else {
            
    // Where you want to save the uploaded images.
            
    $uploadDir 'c:' .DIRECTORY_SEPARATOR'apache' .DIRECTORY_SEPARATOR'htdocs' .DIRECTORY_SEPARATOR'floridafinecars' .DIRECTORY_SEPARATOR'upload'

            
    // Add the AgentID to the original filename
            
    $fileName $uploadDir .DIRECTORY_SEPARATOR$AgentID $imageName;

            
    // Tries to move the uploaded file from the temporary dir to the spesified dir.
            // Using the move_upload_file() function instead of copy() because it's made for
            // this purpose.
            
    if(move_uploaded_file($tmpImageName$fileName)) {
                
    $MyImages[] = $fileName;
            } else {
                
    $errors[$i] = "<b>Image #$i ($imageName) could not be saved.</b>";
            }
        }
    }

    // Echo out any errormessages. The errors are kept in an array so it's
    // possible to echo them out after all the files have been iteratet over.
    // That gives you more flexibility where to echo them out.
    if(!empty($errors)) {
        echo 
    '<strong>The following errror(s) occured:</strong><ul>';
        foreach(
    $errors AS $error) {
            echo 
    "<li>$error</li>";
        }
        echo 
    '</ul>';
    }

    // Check if any images were uploaded
    if(!empty($MyImages)) {
        
    $ImageStr implode('|'$MyImages);
        if(!empty(
    $_POST['OldImages'])) {
            
    $ImageStr .= '|' $_POST['OldImages'];
        }
    // No images were uploaded
    } else {
        
    $ImageStr $_POST['OldImages'];
    }

    $catInfo explode("|"$_POST[SelectCategory]);
    $CategoryID $catInfo[0];
    $SubcategoryID $catInfo[1];
    $SubcategoryName $catInfo[2];
    $q1 "UPDATE discreet_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]'
                "
    ;
    if(
    mysql_query($q1)) {
        echo 
    mysql_error();
    } else {
    // Has commmented out these lines to temporarily get rid of the
    // "Cannot send header" error
    /*
        header("location:info.php?id=$_GET[id]");
        exit();
    */
    }
    ?>
    I've also fixed a bug with the $fileName and $newLocation variables.

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
  •