Isolating user uploaded contents from other users with Yii - php

In my app many users, and they can add articles, articles can contain images, and all images stored in uploads folder, and by default any user can delete any image in folder, certanly its not good, whats is the best way to fix that
(For example store images in uploads//) or something like that?
Problem is - how i can separate user uploads?

Since you included the tag yii have a look at Authentication and Authorization - Yii framework. It has special support on this topic. Try to stick with your frameworks conventions to achieve what you desire first. This way you'll have a conssistent system and the power of frameworks' community.

Related

Codeigniter load view from external folder/domain

I have been trying to get more information regarding this, but was not able to find something yet.
We have Competition Admin Back-ends for multiple Competition Organizers, each within their own CodeInginter folder.
All of these projects have a load of files that they share with the exact content. I was wondering if there is a way of storing these views somewhere on an external domain/folder outside of their CodeIgniter folder, so that I would only need to update and upload one single file instead of doing so for each project.
I do believe that this will be a security risk, so I am not sure if it is even possible, but would make my life a lot easier.
The only way that I could find to do something similar was to use PHP's file_get_contents and echo that to act like the view file
echo file_get_contents("http://myurl.com/statement");
But with this I would have to create a central project to handle these "shared" functions, and not just store the view somewhere.
I guess that this will still work, but was wondering if there could have been another way to do so.
Hope that somebody can shed some light on this.
Thanx in advance

Cakephp: Displaying profile pictures for users in cakephp 2

Hie guys i am still learning cakephp so this question might be easy but im struggling. I have a view.ctp that is currently displaying a buyer's profile like personal details, in addition to this i also want it to display a profile picture for the buyer as well. I have a field in the buyers table called prof_pic which is using longblob data type. I can view the profile of the logged buyer, now i want them to view their profile picture and the personal details as well. How do i do this? Thank you
save image in folder
then you can easily use it ... resize or crop as you like ..
that's simple and easy way :)
You should consider saving your files in the filesystem instead of the database. Florian Krämer from CakeDC did a nice writeup of why to do this. In short:
Storing files in the database is in nearly all cases a bad solution
because when you get the file it has to go its way through the
database connection, which can, specially on servers that are not in
the same network, cause performance problems.
Advantages of storage in the file system:
Easy and direct file access, to parse them (csv, xml...) or manipulate them (images)
You don't need to install any additional software to manage them
Easy to move and mount on other machines
Smaller then stored in a DB
He started an interesting implementation of a plugin to do this. It makes use of the Gaufrette filesystem abstraction layer and makes working with files in Cake much cleaner. A way to scale Images to your needs with the Imagine plugin is also already provided and you're even able to host your images on Amazon S3 and the likes if you're running a high traffic site.

In a web application, what's the best way to store custom user data

We have a web application that we're refactoring. We want to make an environment per version with different users (companies) that share the same codebase.
It know this is a somewhat simple question but I just want to make sure we make the right decision (according to webapp best practice).
Say companya.webapp.com points to /1.00/public
and companyb.webapp.com points to /1.30/public
I'm wondering what the best way is to store custom data from these users. Custom data could be uploaded documents, photos and also generated static data like PDF documents/invoices.
When I migrate a user to a different version I want his data to be available in the other version too. The documents also have a record in the database with the path description.
Would it be OK to do something like this structure:
/data/[companyname]/pictures
/data/[companyname]/documents
/data/[companyname]/documents/pdf
/data/[companyname]/documents/csv
/1.00/public
Sure, use whatever structure you like. There's no real "correct" answer, and it's very hard to do it wrong. Just make sure the permissions are properly set, so that each company can't read each other's files.

Help me deal with the logic behind picture gallery

Using PHP i want to create a picture gallery, i need a few suggestion on what would be the best logical solution for this.
a) create a directory for an album and move all the related pictures into the directory and henceforth follow the same way for other albums
b) keep a record or the path using the database(MySQL) and use the relational table (album).
for the method a . is there any way to deal the picture gallery without actually having the need to use the database or XML or whatsoever(database).?
what is your take on this?
thank you.
IMO the database route is the one to take, as it will be much more extensible and easier to maintain.
If you decide to add in a rating/description/review/[whatever] at a later date you will have the foundations in place.
you can still create a directory for each album - WordPress adopts this kind of practice (/uploads/2010/10) for instance - (directories for each month)
you could do it without a database, through some means of directory traversal and an imaginative naming scheme - if you wanted to sort or search the images some common naming format would be needed. Plus you are very restricted on meta data.
+1 for database from me. You ~can~ even store the images in the DB. but I prefer to keep them as images and just link to the path.
my $0.02
Personally, I would do a combination of both. You will want to move the pictures into a folder structure that makes sense. Whether or not that is by user or by album or what, that is up to you.
You could potentially use method A and ditch the database by keeping each gallery in a properly named folder and then just open that folder and loop through the contents every time you wanted to display the gallery, but it would make your life much more difficult and it wouldn't make much sense.
By using a database, you have all the benefits of a relational data structure... photos can be linked to galleries and tags can be applied to photos.. you can store permissions by photo or by gallery... you have way more options when going with the database.

Best way to handle server-side user files?

I'm trying to make a webapp. The application I am making for myself to help with foreign language translations for classes at my college, and I am hoping to make it available online. All the data that the site saves is in a format like:
section 1
foreign text
translated text
section 2
foreign text
translated text
The app relies on javascript and jquery, so I thought JSON would be a good format for the data. I've got a basic user system set up, I just need to know the best way to handle the projects. What seems easiest is to just have a directory on my site in which there is a folder for every user. Every user's folder would have an individual file for each project they've made. In the load dialog the php will print the list of files in the user's directory so as to make a list of saved projects.
I don't believe this is the best solution; I'm kind of hacking this together as I go along. Would one giant json file for each user be better, or just a pain to code?
I would put everything in a database and not in individual files.
Is there a reason you can´t use a database?
Example:
The simple basic setup with a database would be something with 2 tables:
Users:
user_id
name
etc.
Texts:
project_id
user_id
foreign_text
translated_text
Where the foreign_text and translated_text are of type text.

Categories