2015-10-05 61 views
0

我不擅長於PHP,我想'連接'一個網址,我想在它的末尾添加一個毫秒的時間,所以這個網址是唯一的。連接名稱毫秒時間

完整的URL是這樣的:http://www.justedhak.comlu.com/images/uploaded_images1.jpg 我想毫秒的時間,每次添加到uploaded_images1

慾望的結果是這樣

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

我想我要補充輪()到$ imagename?這是我的代碼

$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')"; 
+2

你需要做一個獨特的名字,這就是它替換該行

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

? @Moudiz –

+0

也許可以幫助你:http://stackoverflow.com/questions/17909871/getting-date-format-m-d-y-his-u-from-milliseconds –

+0

@SubinThomas是唯一的名稱添加到網址。所以url上傳圖片是獨一無二的 – Moudiz

回答

2

我認爲你可以使用uniqid()來創建唯一的字符串。它不只是數字。更改以下行

$imagename="uploaded_images.jpg"; 

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

here約uniqid更多詳細資料()。

也編輯此行。與

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

它的工作,它給了我像這樣'uploaded_images5612cf3a7​​1ecb.png',但請你能告訴我如何將它添加到URL?這是正確的嗎?$ imageurl =「http://justedhak.comlu.com/images/。」$ imagename「」; – Moudiz