【问题标题】:Generating unique urls to submitted pictures?为提交的图片生成唯一的网址?
【发布时间】:2011-11-05 01:33:13
【问题描述】:
Here 是网站。
如您所见,我有个人提交的图片,可以通过单击缩略图查看。这一切都是通过JS完成的。如何做到这一点,以便当有人提交图片时,会为该图片创建一个具有唯一 url 的新页面?
提前致谢。如果您需要我提供任何代码,请告诉我。 :)
【问题讨论】:
标签:
javascript
html
url
unique
【解决方案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