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
2 に答える
私はその種のタスク用の完全なプラグインを作成しましたが、ファイル パスを保存するという考えだけでなく、よりよく考えられています。
ファイルには、ファイルが提供されるときに役立つサイズや MIME タイプなどのメタデータがいくつかあります。したがって、アップロードされたファイルは、それ自体のエンティティとして処理する必要があります。個人的には、レコード内のファイルへのパスを直接保存するのは悪い考えだと思います。後で 2 つの画像が必要になった場合はどうなりますか? path1、path2 などのインクリメント フィールドを追加しますか?
ファイル用に別のテーブルを用意し、レコードをこれらのファイル レコードに関連付ける方が IMO の方が適切です。CakePHP アソシエーションで表現: ユーザー hasOne Avatar や Gallery hasMany Image など。
また、この uploads\username1\pic.jpg のようなパスにファイルを保存すると、同じレベルのファイル システム内に多数のディレクトリとファイルを取得すると、ファイル システムのパフォーマンスの問題により、アプリの速度が低下する可能性があります。
ただし、プラグインの readme.md を確認してください。遭遇する可能性のあるさまざまな種類の問題を解決するために、プラグインがこのようなことを行う理由について詳しく説明しています。