简体   繁体   English

将图像上传到s3并将路径存储在数据库中时出现laravel问题

[英]laravel issue when upload images to s3 and store the paths in database

I am new the this PHP things and I wanna create a article model which has title and some images 我是这个PHP东西的新手,我想创建一个具有标题和一些图像的文章模型

what I can do is save the title to my database but not the uploaded images , even more , I don't know how to upload multiple images with php or should I call laravel ? 我能做的是save the title to my database但不save the title to my database上传的图像, even more , I don't know how to upload multiple images with php or should I call laravel ?

one single image is fine with me and I know the callback will tell me the image address but what indeed should I do to store them in database and relate them in the specific article model ? 一个图像适合我,而且我知道回调函数将告诉我图像地址,但实际上应该怎么做才能将它们存储在数据库中并与特定的文章模型相关联?

many many thanks 非常感谢

Ok let me address this issue, your uploaded image should be renamed using timestamp reason is to avoid name collision. 好,让我解决这个问题,您上载的图片应使用时间戳进行重命名,其目的是避免名称冲突。 Look at this for example $filename_path = md5(time().uniqid()).".jpg"; 例如看$ filename_path = md5(time()。uniqid())。“。jpg”; This ensures that you will always have unique name for the file. 这样可以确保文件始终具有唯一的名称。 Once you rename the file and move to s3 then you save $filename_path into a table. 重命名文件并移至s3之后,将$ filename_path保存到表中。

During retrieval you get the name and search your s3 bucket for the image. 在检索过程中,您将获得名称并在s3存储桶中搜索该图像。

Hope this helps 希望这可以帮助

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

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