简体   繁体   English

如何在mysql中存储用户的个人资料图片

[英]How to store user's profile picture in mysql

I am developing a chat application for iOS.我正在为 iOS 开发一个聊天应用程序。

In this app, the users can set up an image as their profile picture.在这个应用程序中,用户可以将图像设置为他们的个人资料图片。

So my question is, how can i be able to store images in mysql ?所以我的问题是,我怎样才能在 mysql 中存储图像?

I have seen that many people say, just store the link to the image(on device) in mysql, but how will the images be available on different iOS Devices, from a database right ?我看到很多人说,只需将图像(在设备上)的链接存储在 mysql 中,但是图像如何在不同的 iOS 设备上从数据库中可用,对吗?

I have also tried using BLOB, but when the table rows are displayed(json encoded), the value for BLOB field comes out to be NULL.我也尝试过使用 BLOB,但是当显示表行(json 编码)时,BLOB 字段的值显示为 NULL。

Please answer in brief.请简要回答。

Thanks,谢谢,

This is fairly simple :) The physical image will be stored on a server and you will store in your DB only the image name, or the relative path to the image, or however you want it.这相当简单:) 物理图像将存储在服务器上,您将仅在数据库中存储图像名称或图像的相对路径,或者您想要的任何内容。 So, if you like, you will have to store in your DB a "pointer" to that image.因此,如果您愿意,您将不得不在您的数据库中存储一个指向该图像的“指针”。

So:所以:
- Image in folder on the server - 服务器上文件夹中的图像
- In DB -> path/to/file or file_name.format OR if you know you path, and you know your format just file_name - 在 DB -> path/to/file 或 file_name.format 或者如果你知道你的路径,并且你知道你的格式只是 file_name

Hope this helps!希望这可以帮助! :D :D

May be late But I just found way to do that.可能会迟到但我刚刚找到了这样做的方法。

Way 1: Get image from user and rename with the id (Pref. Primary key) and in Your public_html create folder for images.方式 1:从用户获取图像并使用 id(首选主键)并在您的 public_html 创建图像文件夹中重命名。 Set proper permissions for that folder.为该文件夹设置适当的权限。 and save image in that folder and the url of that image will be stored DB column .并将图像保存在该文件夹中,该图像的 url 将存储在 DB 列中。 Like喜欢

https://www.example.com/images/user1.png do in that style. https://www.example.com/images/user1.png采用这种风格。

Way 2: use other things to rename that image like user's email,username etc方式2:使用其他东西重命名该图像,如用户的电子邮件,用户名等

way 3: In above 2 cases it may happen that other users,hackers may try to download images by using IDs,emails etc. That's why , another way you can do is you can generate a hash for profile and check if the hash already exists in column if exits then generate another one.方式 3:在上述 2 种情况下,其他用户、黑客可能会尝试使用 ID、电子邮件等下载图像。这就是为什么,另一种方法是您可以为配置文件生成哈希并检查哈希是否已经存在在列中如果退出然后生成另一个。 Likely I don't think there is possibility of generating similar hashes.but you may check to avoid error in future.可能我不认为有可能生成类似的哈希值。但您可以检查以避免将来出错。 and now rename image using that generated hash.现在使用生成的哈希重命名图像。

You may also reduce size of that link column using only storing generated hash and in your app declare some variables and achieve您还可以仅使用存储生成的哈希来减小该链接列的大小,并在您的应用程序中声明一些变量并实现

https://www.example.com/images/generated_hash.png https://www.example.com/images/generated_hash.png

here the url will be same in all columns excluding that hash key.这里的 url 在所有列中都相同,但不包括该哈希键。 you may only store that hashes.您只能存储该哈希值。

Hope it will help希望它会有所帮助

Reference from : https://www.techupdates.live/how-to-save-profile-picture-in-php-in-5-simple-steps/参考自: https : //www.techupdates.live/how-to-save-profile-picture-in-php-in-5-simple-steps/

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

相关问题 如何在Facebook上获取用户的个人资料图片 - How to get user's profile picture on Facebook 如何获取用户朋友的头像? - How to get Profile picture of User Friend's ?? 如何在 php 中获取 Facebook 用户的个人资料图片 - How to get a Facebook user's profile picture in php 如何从Facebook获取用户的个人资料图片? - How to fetch a user's profile Picture from Facebook? 获取facebook用户的个人资料图片 - Get facebook user's profile picture 如何加载和保存用户的Facebook个人资料图片 - How To Load And Save Facebook Profile Picture Of User 我应该怎么获得的Facebook用户的好友列表,并在PHP他们的个人资料图片的使用图形API? - How should i get Facebook user friend list and their profile picture's using Graph API in PHP? 如何使用PHP保存用户的Facebook个人资料图片到我的域/网站数据 - How to save save user's facebook profile picture to my domain/website data using php 如何返回存储在我的文件中的用户个人资料图片(保存在/ tmp文件夹中以将其放置在此处以进行临时提取) - How to return User's profile picture that is stored in my filestyem (is /tmp folder save to put it there for temporary extraction) 如何存储个人资料视图以显示查看过其个人资料的每个用户? - How to store Profile Views to show each user who's viewed their profile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM