<tfoot id='B0cLT'></tfoot>
<legend id='B0cLT'><style id='B0cLT'><dir id='B0cLT'><q id='B0cLT'></q></dir></style></legend>
  • <small id='B0cLT'></small><noframes id='B0cLT'>

        <i id='B0cLT'><tr id='B0cLT'><dt id='B0cLT'><q id='B0cLT'><span id='B0cLT'><b id='B0cLT'><form id='B0cLT'><ins id='B0cLT'></ins><ul id='B0cLT'></ul><sub id='B0cLT'></sub></form><legend id='B0cLT'></legend><bdo id='B0cLT'><pre id='B0cLT'><center id='B0cLT'></center></pre></bdo></b><th id='B0cLT'></th></span></q></dt></tr></i><div id='B0cLT'><tfoot id='B0cLT'></tfoot><dl id='B0cLT'><fieldset id='B0cLT'></fieldset></dl></div>
          <bdo id='B0cLT'></bdo><ul id='B0cLT'></ul>

        使用唯一文件名通过 php 上传图像

        upload images through php using unique file names(使用唯一文件名通过 php 上传图像)
        <legend id='a1iAd'><style id='a1iAd'><dir id='a1iAd'><q id='a1iAd'></q></dir></style></legend>
            <tbody id='a1iAd'></tbody>
          • <bdo id='a1iAd'></bdo><ul id='a1iAd'></ul>
            <tfoot id='a1iAd'></tfoot>

              • <i id='a1iAd'><tr id='a1iAd'><dt id='a1iAd'><q id='a1iAd'><span id='a1iAd'><b id='a1iAd'><form id='a1iAd'><ins id='a1iAd'></ins><ul id='a1iAd'></ul><sub id='a1iAd'></sub></form><legend id='a1iAd'></legend><bdo id='a1iAd'><pre id='a1iAd'><center id='a1iAd'></center></pre></bdo></b><th id='a1iAd'></th></span></q></dt></tr></i><div id='a1iAd'><tfoot id='a1iAd'></tfoot><dl id='a1iAd'><fieldset id='a1iAd'></fieldset></dl></div>
              • <small id='a1iAd'></small><noframes id='a1iAd'>

                • 本文介绍了使用唯一文件名通过 php 上传图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在借助 phonegap 编写移动应用程序.我希望这个应用程序具有的少数功能之一是能够捕获图像并将其上传到远程服务器......

                  I am currently in the process of writing a mobile app with the help of phonegap. One of the few features that I would like this app to have is the ability to capture an image and upload it to a remote server...

                  我目前的图像捕获和上传/发送电子邮件部分可以使用已编译的 apk 正常工作...但在我的 php 中,我目前将图像命名为图像 [插入从 10 到 20 的随机数]...问题这里是数字可以重复并且图像可以被覆盖......我已经阅读并考虑过只使用rand()并从0到getrandmax()中选择一个随机数,但我觉得我可能有同样的机会文件覆盖...我需要每次都以唯一的名称将图像上传到服务器,无论如何...所以 php 脚本将检查服务器已有的内容并写入/上传图像具有唯一的名称...

                  I currently have the image capturing and uploading/emailing portion working fine with a compiled apk... but in my php, I am currently naming the images "image[insert random number from 10 to 20]... The problem here is that the numbers can be repeated and the images can be overwritten... I have read and thought about just using rand() and selecting a random number from 0 to getrandmax(), but i feel that I might have the same chance of a file overwriting... I need the image to be uploaded to the server with a unique name every-time, no matter what... so the php script would check to see what the server already has and write/upload the image with a unique name...

                  除了rand()"还有什么想法吗?

                  any ideas other than "rand()"?

                  我也在考虑可能为每张图片命名...img + 日期 + 时间 + 随机 5 个字符,其中包括字母和数字...所以如果一张图片是在 3 月凌晨 4:37 使用应用程序拍摄的2013 年 2 月 20 日,当上传到服务器时,图像将被命名为img_03-20-13_4-37am_e4r29.jpg"......我认为这可能有效......(除非有更好的方法)但我相当新到 php 并且不明白如何写这样的东西......

                  I was also thinking about maybe naming each image... img + date + time + random 5 characters, which would include letters and numbers... so if an image were taken using the app at 4:37 am on March 20, 2013, the image would be named something like "img_03-20-13_4-37am_e4r29.jpg" when uploaded to the server... I think that might work... (unless theres a better way) but i am fairly new to php and wouldn't understand how to write something like that...

                  我的php如下...

                  print_r($_FILES);
                  $new_image_name = "image".rand(10, 20).".jpg";
                  move_uploaded_file($_FILES["file"]["tmp_name"], "/home/virtual/domain.com/public_html/upload/".$new_image_name);
                  

                  感谢任何帮助...提前致谢!另外,如果有任何进一步的信息我可能会遗漏,请告诉我......

                  Any help is appreciated... Thanks in advance! Also, Please let me know if there is any further info I may be leaving out...

                  推荐答案

                  你可能要考虑 PHP 的 uniqid() 函数.这样,您建议的代码将如下所示:

                  You may want to consider the PHP's uniqid() function. This way the code you suggested would look like the following:

                  $new_image_name = 'image_' . date('Y-m-d-H-i-s') . '_' . uniqid() . '.jpg';
                  // do some checks to make sure the file you have is an image and if you can trust it
                  move_uploaded_file($_FILES["file"]["tmp_name"], "/home/virtual/domain.com/public_html/upload/".$new_image_name);
                  

                  另外请记住,您的服务器的随机函数并不是真正随机的.如果您确实需要随机的东西,请尝试 random.org.随机随机随机.

                  Also keep in mind that your server's random functions are not really random. Try random.org if you need something indeed random. Random random random.

                  UPD:为了在您的代码中使用 random.org,您必须向他们的服务器发出一些 API 请求.相关文档可在此处获得:www.random.org/clients/http/.

                  UPD: In order to use random.org from within your code, you'll have to do some API requests to their servers. The documentation on that is available here: www.random.org/clients/http/.

                  调用示例为:random.org/integers/?num=1&min=1&max=1000000000&col=1&base=10&format=plain&rnd=new.请注意,您可以更改 minmax 和其他参数,如 文档.

                  The example of the call would be: random.org/integers/?num=1&min=1&max=1000000000&col=1&base=10&format=plain&rnd=new. Note that you can change the min, max and the other parameters, as described in the documentation.

                  在 PHP 中,您可以使用 GET 请求.php" rel="noreferrer">file_get_contents() 函数,cURL 库,甚至是套接字.如果您使用的是共享主机,您的帐户应该可以使用并启用传出连接.

                  In PHP you can do a GET request to a remote server using the file_get_contents() function, the cURL library, or even sockets. If you're using a shared hosting, the outgoing connections should be available and enabled for your account.

                  $random_int = file_get_contents('http://www.random.org/integers/?num=1&min=1&max=1000000000&col=1&base=10&format=plain&rnd=new');
                  var_dump($random_int);
                  

                  这篇关于使用唯一文件名通过 php 上传图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  PHP Upload File Validation(PHP 上传文件验证)
                  PHP Error - Uploading a file(PHP 错误 - 上传文件)
                  How can I write tests for file upload in PHP?(如何在 PHP 中编写文件上传测试?)
                  php resizing image on upload rotates the image when i don#39;t want it to(php在上传时调整图像大小会在我不想要它时旋转图像)
                  How to send additional data using PLupload?(如何使用 PLupload 发送附加数据?)
                  change button text in js/ajax after mp4 =gt;mp3 conversion in php(在 php 中的 mp4 =gt;mp3 转换后更改 js/ajax 中的按钮文本)

                  <i id='z25lb'><tr id='z25lb'><dt id='z25lb'><q id='z25lb'><span id='z25lb'><b id='z25lb'><form id='z25lb'><ins id='z25lb'></ins><ul id='z25lb'></ul><sub id='z25lb'></sub></form><legend id='z25lb'></legend><bdo id='z25lb'><pre id='z25lb'><center id='z25lb'></center></pre></bdo></b><th id='z25lb'></th></span></q></dt></tr></i><div id='z25lb'><tfoot id='z25lb'></tfoot><dl id='z25lb'><fieldset id='z25lb'></fieldset></dl></div>
                  • <bdo id='z25lb'></bdo><ul id='z25lb'></ul>
                  • <tfoot id='z25lb'></tfoot>
                      <tbody id='z25lb'></tbody>

                          <legend id='z25lb'><style id='z25lb'><dir id='z25lb'><q id='z25lb'></q></dir></style></legend>

                          <small id='z25lb'></small><noframes id='z25lb'>