473,385 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

uploading multi-images without name duplication

I am trying to upload multi-images I am using this script everything is fine and the images uploaded successfully the problem here is I don't want to duplicate the images name so I used this script to avoid this but no luck
any idea

this is my code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if(isset($_POST['submit'])){
  3. $target = '../images/Projects/';
  4.     $num=1;
  5.     $projectID=$p;
  6.     foreach ($_FILES["img"]["error"] as $key => $error){
  7.         if ($error==UPLOAD_ERR_OK){
  8.             $tmp_name = $_FILES["img"]["tmp_name"][$key];
  9.             $name = $_FILES["img"]["name"][$key];
  10.             move_uploaded_file($tmp_name, "$target/$name");
  11.  
  12.             if(file_exists($name)){
  13.               $duplicate_filename = TRUE;
  14.             $i=0;
  15.             while($duplicate_filename){
  16.             $filename_data=explode(".", $_FILES['img']['name']);
  17.             $new_filename=$filename_data[0] . "_" . $i . "." . $filename_data[1];
  18.             $_FILES['img']['name']=$new_filename;
  19.             $name="$target".$_FILES['img']['name']."";
  20.             if(file_exists($name))
  21.             {
  22.             $i++;
  23.             }
  24.             else
  25.             {
  26.             $duplicate_filename=FALSE;
  27.         }
  28.     }
  29. }
  30.  
  31.             $putData = "INSERT INTO projects_images (id, image, image_id)VALUE('', '$name', '$projectID')";
  32.               $result = $db->query($putData)or die($db->error);
  33.             if($result){header('Location:index.php?id=2&proid=3&p='.$p.'&msg=Images has been uploaded successfully, carry on upload more images if you like');
  34.             }else{echo"Error";
  35.             }
  36.         }
  37.     } 
  38. }
  39. ?>
Jan 15 '14 #1
3 1287
You can just add mktime() value to every image name.
Jan 15 '14 #2
vspiridonov can you please send me an exsample on what you are saying
Jan 15 '14 #3
Expand|Select|Wrap|Line Numbers
  1. $new_filename=$filename_data[0] . "_" . mktime() . "." . $filename_data[1];
Jan 20 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Saurabh | last post by:
Hi all, I am using php3. For uploading a file i put <input type=file name=thesisfile> in the html file. now in the php3 file that i am using i used echo $thesisfile_type; echo...
6
by: Chamomile | last post by:
can anyone point me to some straightforward information on file uploading without using an html form? That is, direcly from within a php script. if I know the local path etc. to a particular...
3
by: djc | last post by:
I need a way to upload a file to the server without any help from a user. does anyone have an example i could use. Thanks
2
by: John | last post by:
Hi, I have a data driven application which has some generalized components. So, for reuse, I am building the components so they can be reused in other projects ... it takes almost no extra...
3
by: perfb | last post by:
have a C++ DLL that needs to be called be external non-C app that uses C interface, but cant figure out how to export C++ DLL functions without name mangling. if I declare ...
5
by: Ariel Dolan | last post by:
Can I use HtmlInputFile to only get the selected file name but not actually upload the file? Clicking the control's Browse button let's the user select a file. All I need is the HtmlInputFile...
1
by: joe | last post by:
Is there a way to deploy a web site with several physical aspx pages left out? Say the client requests ABC.aspx. I want to intercept the request (which I already do with a custom HttpModule) and...
4
by: Joachim | last post by:
Hi. I have a function that swap images. But in the image element i use the tag "name" to give name that i send to my java script function: <img src="greensmiley.jpg" name="smiley" alt="gubbe"...
0
by: Raj | last post by:
Hello, I am planning to provide the Pause/Resume while uploading files. Our site is using both java applet and activex to do this. The list of selected files will be stored in an encrypted...
3
by: Yousef Altaf | last post by:
hay I have this code to upload images it works OK bu there is 2 things not working 1- when the image has the same name it doesn't display the message "A file of the same name already exists" it just...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.