Multiple images rename & uploading in PHP

lock

I am using the following code to upload set of images into the server, I am renaming the files while uploading, but when I am trying to uploading multiple files its automatically replacing the files, instead I need the other files to be named with 2, 3, 4, etc. in the end of the file name.

<input type="file" name="upl" />
<input type="submit" value="submit" />

$_SESSION['imgrand'] is the random string generated and passed over session.

function findexts ($filename) 
 { 
 $filename = strtolower($filename) ; 
 $exts = split("[/\\.]", $filename) ; 
 $n = count($exts)-1; 
 $exts = $exts[$n]; 
 return $exts; 
 } 
 $ext = findexts ($_FILES['upl']['name']) ; 
 $ran = $_SESSION['imgrand'];
 $ran2 = $ran.".";
 $target = "uploads/";
 $target = $target . $ran2.$ext; 

 if(move_uploaded_file($_FILES['upl']['tmp_name'], $target)) 
 {
 echo "The file has been upl as ".$ran2.$ext;
 } 
 else
 {
 echo "Sorry, there was a problem uploading your file.";
 }

For example if the random string is jahkhakshdkjshdjksahds I need the images should be named as jahkhakshdkjshdjksahds1.ext, jahkhakshdkjshdjksahds2.ext, jahkhakshdkjshdjksahds3.ext, jahkhakshdkjshdjksahds4.ext, jahkhakshdkjshdjksahds5.ext likewise?

moskito-x

test for a existing file before overright.

...
$ext = findexts ($_FILES['upl']['name']) ; 
$ran = $_SESSION['imgrand'];
$target = "uploads/".$ran;

for($i=1;$i < 100;$i++) {
  $filename = $target.$i.".".$ext;
  if (file_exists($filename)) {
    continue;
  } else {
    if(move_uploaded_file($_FILES['upl']['tmp_name'], $filename)) 
    {
    echo "The file has been upl as : ".$filename;
    break; 
    } 
    else
    {
    echo "Sorry, there was a problem uploading your file: ".$filename;
    break;
    }
  } // not file_ex
} // for
...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Multiple images rename & uploading in PHP

From Dev

PHP: Uploading multiple images to imgur at once

From Dev

PHP: Uploading multiple images at the same time

From Dev

Uploading multiple images in webservice using PHP

From Dev

Uploading multiple images with volley?

From Dev

Uploading multiple images in codeigniter?

From Dev

Uploading multiple images with paperclip?

From Dev

Uploading multiple images with Django

From Dev

Uploading multiple images in codeigniter?

From Dev

Django multiple images not uploading

From Dev

Uploading multiple images one to each row PHP and Mysqli db

From Dev

Windows rename multiple images

From Dev

Rename and move multiple Images

From Dev

Uploading Multiple Images using CarrierWave

From Dev

All images not uploading in multiple images upload

From Dev

Wont uploading bigger images PHP

From Dev

PHP: Images file is not uploading on the server?

From Dev

Renaming multiple images with .rename and .endswith

From Dev

PHP foreach($images as $image) not uploading images

From Dev

How to Rename images while uploading in add / remove dynamic fields

From Dev

Uploading multiple images from Share Extension

From Dev

Uploading multiple images with other parameters in Swift

From Dev

Django REST: Uploading and serializing multiple images

From Dev

Uploading multiple images to mysql database on Apache server

From Dev

multiple images uploading and converting them to thumbnails in cakephp

From Dev

Uploading multiple images using SRWebClient in Swift

From Dev

uploading/downloading multiple images the right way?

From Dev

Rails and carrierwave uploading multiple images fails

From Dev

Issues with Uploading Multiple files with PHP

Related Related

HotTag

Archive