简体   繁体   English

PHP图像上传器需要它很简单

[英]php image uploader need it to be simple

I need to get this done very quickly. 我需要尽快完成这项工作。 What's an easy way to do image uploading in php...I have a script atm but if an image with the same name comes it'll overwrite it. 用php上传图片的简单方法是什么...我有一个脚本atm,但是如果有一个同名的图片会覆盖它。

Basically I just want to be able to use the form field file to select an image and upload and maybe rename it somehow. 基本上,我只希望能够使用表单字段文件选择图像并上传并以某种方式重命名。 Then put the location into a database to retrieve when needed. 然后将位置放入数据库以在需要时进行检索。

Any tips or ideas on how to do this? 有关如何执行此操作的任何提示或想法? Don't have a lot of time to get this done. 没有太多时间来完成此任务。

http://www.google.co.za/search?sourceid=chrome&ie=UTF-8&q=php+image+upload http://www.google.co.za/search?sourceid=chrome&ie=UTF-8&q=php+image+upload

http://www.plupload.com/ - is also a good way to do this. http://www.plupload.com/-也是执行此操作的好方法。 Doing something 做某事

very quickly ... the easy way 很快...简单的方法

Sounds to me like you are looking for the easy way out. 在我看来,您正在寻找简便的出路。 Please remember that we are not here to give you your code solution, but merely as an advisory panel to help you get over some obstacles in your current (already tried to make it work) code. 请记住,我们并不是在这里为您提供代码解决方案,而只是作为咨询小组来帮助您克服当前(已经尝试使其生效)代码中的一些障碍。 If you read up a bit its real easy, thats the reason for documentation on everything, especially PHP and file uploading. 如果您读了一下它的真正简单之处,那就是所有内容都提供文档的原因,尤其是PHP和文件上传。

:) :)

Seems to me right now, your script has a security issue as well. 现在看来,您的脚本也存在安全问题。

Append a unique hash to the end of the filename before you save it. 保存文件名之前,在文件名的末尾附加一个唯一的哈希。 That way no one can overwrite your files. 这样,没人可以覆盖您的文件。

Can you just append uniqid() to the filename..? 您可以将uniqid()附加到文件名..吗?

$target = "files/";

// Upload the file to directory
$url = basename($_FILES['uploadedfile']['name']);
$name = str_replace(' ', '_', $url);
$target .= strtolower($name . uniqid());

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target))
{
    echo 'File has been uploaded<br />
    <a href="' . $target . '">http://yoursite.com/directory/' . $target . '</a>';
}

Obviously still needs to be made more secure. 显然仍然需要使其更加安全。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM