Since I am just experimenting on this, (only localhost) I may like to ask for some ideas(since nothing is really coming out of my mind) about letting a user, who is going to, for example, register to a mini-social-networking site, with a corresponding username/password, personal details, etc. I would upload the image, and save it to a folder(ON MY HARD DRIVE be it Drive C:\ or D:), for example '/images/username' and the full path of the folder would be the one inserted to a row named img_dir (of course it is a string, instead of putting it as a BLOB, so later i would just use img src="path"). I would not mind where it will be going to be saved. But since I am new to cakephp i haven't really grasped the idea of what I am going to do. I have no problems about registering/login sessions. This was easy in C# but I am too stupid for PHP maybe? :P
问问题
403 次
2 回答
0
于 2013-08-10T16:33:50.710 回答
0
我已经为这种任务编写了一个完整的插件,它比保存文件路径的想法更经过深思熟虑。
一个文件有更多的元数据,比如它的大小和 mime 类型,这在提供文件时很有用。所以上传的文件应该作为它自己的实体来处理。我个人认为直接将路径保存到它所属的记录中的文件是一个坏主意。如果您稍后需要两张图片怎么办?添加像path1,path2这样的递增字段?
IMO 最好有一个单独的文件表并将记录与这些文件记录相关联。在 CakePHP 关联中表示:例如 User hasOne Avatar 或 Gallery hasMany Image。
如果您在文件系统的同一级别中获得大量目录和文件,那么将文件保存在像这样的路径 uploads\username1\pic.jpg 可能会导致应用程序变慢,因为文件系统性能问题。
但是,请检查我的插件 readme.md ,还有更多关于它为什么会像解决您可能遇到的不同类型的问题那样做的事情。
于 2013-08-11T11:25:50.907 回答