0

I am not good with php ,I want to 'concatenate` a url, I want to add a time of millisecond at the end of it so the url be unique.

the full url is like this: http://www.justedhak.comlu.com/images/uploaded_images1.jpg I want everytime add millisecond time to uploaded_images1

the desire result like this

...images/uploaded_images3214100.jpg
...images/uploaded_images3321490.jpg
...images/uploaded_images5216100.jpg
...images/uploaded_images6328490.jpg

I guess I have to add round() to $imagename ?this is my code

$con = mysqli_connect($host,$uname,$pwd,$db);


$image=$_POST['image'];
$imagename="uploaded_images.jpg";
$imageurl="http://justedhak.comlu.com/images/."$imagename"";

     $binary=base64_decode($image);
    header('Content-Type: bitmap; charset=utf-8');
    $file = fopen($imagename, 'wb');
    fwrite($file, $binary);
    fclose($file);

$sql = "insert into image (description,categorie,path) values ('$categorie','$description','$imageurl')";
Moudiz
  • 7,211
  • 22
  • 78
  • 156

1 Answers1

2

I think you can use uniqid() to create unique strings. Its not just numbers. Change the following line

$imagename="uploaded_images.jpg";

with

$imagename = uniqid("uploaded_images").".png";  //unique string with prefix of "uploaded_images".

Look here for more details about uniqid().

Also edit this line. Replace this line

$imageurl="http://justedhak.comlu.com/images/."$imagename"";

with

$imageurl = "http://justedhak.comlu.com/images/".$imagename;
Subin Thomas
  • 1,408
  • 10
  • 19
  • it worked it gave me like this `uploaded_images5612cf3a71ecb.png` but please can you tell me in php how to add it to url ? is this correct ?$imageurl="http://justedhak.comlu.com/images/."$imagename""; – Moudiz Oct 05 '15 at 19:29