开发者

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.

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.plupload.com/ - is also a good way to do this. 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.

:)


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..?

$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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜