图像上传器使用增量图像名称

I am using a php multiple image uploader fine - the code is below. I am trying to modify it to assign incremental image names to the batch of images eg. Image1.jpg, Image2.jpg, Image3.jpg etc rather than a random name. I have tried changing the random code to a variable but no luck. Can anyone please help.

$ThumbSquareSize        = 125; //Thumbnail will be 200x200
$BigImageMaxSize        = 600; //Image Maximum height or width
$ThumbPrefix            = "thumb_"; //Normal thumb Prefix
$Reference_No           = $_POST['Reference_No'];
$DestinationDirectory   = 'properties/'.$Reference_No.'/'; //Upload Directory ends with / (slash)
$Quality                = 75;

//ini_set('memory_limit', '-1'); // maximum memory!

foreach($_FILES as $file)
{
// some information about image we need later.
$ImageName      = $file['name'];
$ImageSize      = $file['size'];
$TempSrc        = $file['tmp_name'];
$ImageType      = $file['type'];


if (is_array($ImageName))
{
    $c = count($ImageName);

    echo  '<ul>';

    for ($i=0; $i < $c; $i++)
    {
        $processImage           = true;
        $RandomNumber           = rand(0, 9999999999);  // We need same random name for both files.

        if(!isset($ImageName[$i]) || !is_uploaded_file($TempSrc[$i]))
        {
            echo '<div class="error">Error occurred while trying to process <strong>'.$ImageName[$i].'</strong>, may be file too big!</div>'; //output error
        }
        else
        {
            //Validate file + create image from uploaded file.
            switch(strtolower($ImageType[$i]))
            {
                case 'image/png':
                    $CreatedImage = imagecreatefrompng($TempSrc[$i]);
                    break;
                case 'image/gif':
                    $CreatedImage = imagecreatefromgif($TempSrc[$i]);
                    break;
                case 'image/jpeg':
                case 'image/pjpeg':
                    $CreatedImage = imagecreatefromjpeg($TempSrc[$i]);
                    break;
                default:
                    $processImage = false; //image format is not supported!
            }
            //get Image Size
            list($CurWidth,$CurHeight)=getimagesize($TempSrc[$i]);

            //Get file extension from Image name, this will be re-added after random name
            $ImageExt = substr($ImageName[$i], strrpos($ImageName[$i], '.'));
            $ImageExt = str_replace('.','',$ImageExt);

            //Construct a new image name (with random number added) for our new image.
            $NewImageName = $RandomNumber.'.'.$ImageExt;

            //Set the Destination Image path with Random Name
            $thumb_DestRandImageName    = $DestinationDirectory.$ThumbPrefix.$NewImageName; //Thumb name
            $DestRandImageName          = $DestinationDirectory.$NewImageName; //Name for Big Image

            //Resize image to our Specified Size by calling resizeImage function.
            if($processImage && resizeImage($CurWidth,$CurHeight,$BigImageMaxSize,$DestRandImageName,$CreatedImage,$Quality,$ImageType[$i]))
            {
                //Create a square Thumbnail right after, this time we are using cropImage() function
                if(!cropImage($CurWidth,$CurHeight,$ThumbSquareSize,$thumb_DestRandImageName,$CreatedImage,$Quality,$ImageType[$i]))
                    {
                        echo 'Error Creating thumbnail';
                    }
                    /*
                    At this point we have succesfully resized and created thumbnail image
                    We can render image to user's browser or store information in the database
                    For demo, we are going to output results on browser.
                    */

                    //Get New Image Size
                    list($ResizedWidth,$ResizedHeight)=getimagesize($DestRandImageName);

$DestinationDirectory   = 'properties/'.$Reference_No;

                    echo '<li><table width="100%" border="0" cellpadding="4" cellspacing="0">';
                    echo '<tr>';
                    echo '<td align="center"><img src="'.$DestinationDirectory.$ThumbPrefix.$NewImageName.'" alt="Thumbnail" height="'.$ThumbSquareSize.'" width="'.$ThumbSquareSize.'"></td>';
                    echo '</tr><tr>';
                    echo '<td align="center"><img src="'.$DestinationDirectory.$NewImageName.'" alt="Resized Image" height="'.$ResizedHeight.'" width="'.$ResizedWidth.'"></td>';
                    echo '</tr>';
                    echo '</table></li>';
                    /*
                    // Insert info into database table!
                    mysql_query("INSERT INTO myImageTable (ImageName, ThumbName, ImgPath)
                    VALUES ($DestRandImageName, $thumb_DestRandImageName, 'uploads/')");
                    */

            }else{
                echo '<div class="error">Error occurred while trying to process <strong>'.$ImageName[$i].'</strong>! Please check if file is supported</div>'; //output error
            }

        }

    }
    echo '</ul>';
    }
}

you have 2 options

  1. save the number to a file and read the file next time and add to it
  2. keep a list of files in database table and get the last files index and add to it

You already have a for loop incrementing the integer variable $i, so change this:

//Construct a new image name (with random number added) for our new image.
$NewImageName = $RandomNumber.'.'.$ImageExt;

to the following code:

//Construct a new image name (with random number added) for our new image.
$NewImageName = 'Image'.$i.'.'.$ImageExt;