2011-11-05 81 views
-1

Here是該網站。爲提交的圖片生成獨特的網址?

正如你所看到的,我有單獨提交的圖片,可以通過點擊縮略圖來查看。這一切都是通過JS完成的。我該如何做到這一點,以便有人提交圖片時,會爲該圖片創建一個具有唯一網址的新網頁?

在此先感謝。請讓我知道是否有任何你需要從我的代碼。 :)

+2

代碼將會很好 –

+0

該網站在哪裏?你在服務器端使用什麼,這是重要的。 –

+0

這是什麼,另一個[imgur](http://imgur.com)克隆? –

回答

1

您可以將每個名稱更改爲隨機文件名。 (假設你已經寫入的圖像使用$imagefilename變量文件,並且擴展.JPG)

<?php 
    //The image, defined as $image 
    //Write the image to a file, using the $imagefilename variable for a name. 
    $webpagefilename = rand(); 
    $imagefilename = $webpagefilename.".jpg"; 
    $myFile = $filename.".html"; 
    $fh = fopen($myFile, 'w') or die("Error: Can't open file"); 
    $stringData = "<img src='".$imagefilename."' />"; 
    fwrite($fh, $stringData); 
    fclose($fh); 
?> 

嘗試。 :P