I am building a webpage using PHP to search within my database. I am able to do a query and get the data to show on my page.
I also have a picture that is related to each record. Let's say something like a picture ID for each employee. I am wondering what is the best way to store and retrieve pictures in order to get it show using PHP.
Is there a way to store all the pictures in the subfolder like " image" and retrieve the pictures using PHP? I tried to search around on the internet, but I get confused.
Also, when I type something in the search box and click the button, is there a way to keep the input in the search box without erasing it?
Thank you very much.
The typical way is exactly what you said - store all the pictures in a folder and store their path in the database (or be able to build their path from their id or something). You just need to create a script to insert the record into your database when you add the picture to the file system.
You can store the pictures in database itself. You can have a field in the user table called 'pic' with data type 'blob'. This can store the image for every user. This link will get you started:
http://mrarrowhead.com/index.php?page=store_images_mysql_php.php
As, correctly pointed out by #shaheer in the comment below, this is not a recommended practice.
'Attaching' images to your class objects by storing the web-url in the database as a attribute of that class is a better way. There is a excellent Ruby gem that I use for this frequently its called Carrierwave. Its workflow should be good for you to get Idea on how to do this in php.
I am not sure if there are any good alternatives for php (I am not a php dev) but a quick search returned this: Attachy. This is specifically to manage 'uploads', but you can use the same technique on existing images that you want to attach to your class.
Related
I am trying to create a php page that reads a list of films from a database and displays the corresponding images in a table.
I've found quite a few examples of this, but havent successfully been able to implement it yet.
Has anyone got a link to a good tutorial on doing this or perhaps code you've used yourself?
so my images are stored in a folder 'images' on a server, and each entry in my table contains the colulmn 'imagelocation' which has a relative location, like "images/film1.jpg".
Ultimately the images will be clickable and will open a lightbox type view with the image and full info about the film.
any help appriciated!
I'm using PHP and MySQL, and don't know where to start with how to set up profile pictures.
It seems all other user data can be held in the mysql table, but I don't think I can put pictures into a mysql table. So how do profile pictures generally work?
You can put pictures in a database (using a BLOB field), but I wouldn't, due to the performance hit.
Store the images on the filesystem with PHP, and just store the ID of the picture in the database.
I think that what is usually done is set up an upload system for users to upload their images. You just have to link this image with the user by naming it with something like a user ID.
Then you just have to store a link to the uploaded picture in your database, this way you could also imagine allowing user to use remote images although this might not be a good idea.
But as said, the MySQL BLOB field allows storing pictures.
I have created a basic website that uses MySQL and PHP to store the pages in a database following some online tutorial. The pages are used to dynamically create the menu , which I like. The main point of the site is to be an online gallery of paintings.
I can easily create this site statically in HTML, but I kind of want to try doing it dynamically. I can store the jpegs in a folder on the server and have HTML links within the page content. But is there any other way of doing it? Would it be sensible to store all the picture data and file names in a database, so that it gets retrieved when a user clicks an option from the menu?
Any thoughts would be appreciated
Research a bit more, you have one of the most answered problem in existence.
Why do you want to do it dynamically if static HTML is sufficient for your use. To make it cool is not the right reason.
About storing the jpegs in database read this article.
To BLOB or Not To BLOB - Microsoft Research
research.microsoft.com/apps/pubs/default.aspx?id=64525
I just need a bit of advice on what direction to go with something I am creating.
It is a simple php based webpage for our sports and social members in our office, allowing them to create, edit, view and delete events for all members to see. Events like day trips, bbq's and all kinds of things like that.
So far I have it all working as I would like, other than one thing, being the event logos.
At present, the events are all stored in a mysql database, in one table, with a column for every aspect of the event; time, date, price, venue etc etc.
I also have two columns for the event logos, one for the venue logo, and one for the general event logo.
What I need advice on, is the best way to create a page that allows a user to upload an image to the server, browse the images already uploaded, select one, and have it's file path entered into a text input when creating the event.
Could someone offer their suggestions on the best way to go about this, or offer an alternative method for selecting and inputting a logo for the event?
Thanks
The Uploadify jQuery plugin works really well for batch and/or AJAX uploads. The way I'd handle your situation would be this:
Show all images on the same page with the form, and give each image a related radio button with the image path as the button's value, so the user simply checks the image they want to use,
If the user wants to upload images, use the Uploadify plugin and it's AJAX callback functions to dynamically populate the existing list of radio buttons.
The comment I made on your question, asking wether you store images (or their file paths) was because I think it would be much easier (and cleaner) for you to retrieve a list of uploaded images by querying a database. Personally, I don't store images in a database, only their file paths, and use PHP to handle any images that need to be deleted or moved. It's easier to assing images to other entities (especially in many-to-many relationships) that way.
If you don't want to store images' data in a separate table, I guess you'd have to use PHP file system functions to get a list of files already uploaded (glob comes to mind, although there could be better functions or this).
EDIT:
There is also a very good AJAX file browser plugin - ckFinder, but I have very little experience with it and can't really comment on its workflow, but if you find it to be a more elegant solution, you should try it out.
if i could understand your question you want to associate the image with the event i.e tag the image with the event right ??
you can use jquery's attr() function to grab the src of img and put it in input field
I ended up storing the images in the database itself.
Saved some hassle on the file path side of things.
I am making an application in which every user has to sign in first and then he can access his home page. Now on the home page, I have given an option of uploading an image. Now if the user is uploading one image I am storing the full path of the uploaded image into a database and from there I can display the image easily by an img tag...
But what should I do when the user want to upload many images? Then how should I store their full paths in a database for the same user. Give me an idea just like Orkut or Facebook. Should I make a different table with named images and should I store images in different rows with the same username. What should I do?
I don't know the logic. What should I do? How can I upload many images and how can I store their path and what will be the wisest method and how do I display many images on one page (I can display one)?
You can make a folder, named after user name and id and put all their images there.
To display many images on one page, just add more <img> tags to the page.
This seems to be more of a design question than a PHP question. I would create a separate table to store all paths, this is more normalized.
You still need to handle the UI, but if you are doing a sort of gallery then that is fairly simple with some jQuery sideshows or something like that.
Yes, you want to use a separate table to store the image paths. You'll most likely want a record ID, the User ID, and the path to the image. You could also add a field to contain the sorting order for the images.
Having the sorting order field will allow you to page through the photos if there is more than one page of photos.
Your thinking is correct where you suggest creating a separate table with rows containing the image path and the username. The concept that you are dealing with is called cardinality. I'd recommend that you take a few minutes to read about this concept, since it is so important to database design.
In this case, you're talking about a one-to-many relationship between the user and the images.