I'm trying to do this with cakephp.
I will have a form that will allow the user to type in a school name, school phone number, and also upload a pre determined sized image as a thumbnail for that school. Then when that form is submitted, on the webpage I want it to display that thumbnail with the associated school.
How do I accomplish uploading a image through cakephp, and somehow associated that in my mySQL database?
Adding onto question #1, how would I display that image in a view?
In order to link an image to your database, you can also use the following method:
Create an "img" column in your table
When uploading your image to the server (you can refer to https://stackoverflow.com/questions/9673408/simple-tutorial-for-file-uploads-in-cakephp-2-0 for that) save your pathname in a variable
Save this variable (example "http://www.domain.com/gallery/image1.jpg") in the "img" column in your table
Then when displaying the image in your view, just use this value from the database:
<img src="<?php echo $data.img ?>" />
(above code example is not with cakephp)
There is a great plugin for handling image uploads which will do all this for you.
https://github.com/josegonzalez/upload
It will also associate the upload with a Model, either on the model or joined.
To display images in the view, you should use the Html helper.
$this->Html->image('../files/<Model>/<field>);
Related
Hi i am working on a photo gallery. Here all images are coming from mysql database table. The images are uploaded from the admin panel. I am using php to upload and fetch images from database table. Till here all things are working fine. Now i have to implement a system where user should be able to define the position of the image in the image gallery and image positions should be swiped with one another image. In the gallery page I am showing 16 images in four rows and after that pagination starts. So will it be possible to implement such a system in my image gallery?
If I understand what you want to do correctly then you might want to check out this jQuery plugin: http://isotope.metafizzy.co/
Im trying to figure out the best way to add captions to a set of photos. This is the process:
User uploads photos (Ex: 10)
After upload is successful (save in a folder labeled by their username), the page refreshes and the photos appear in a list with a "caption" input next to it.
Users type in their captions and click "Submit"
The photo captions are saved
What Im having a hard time figuring out is how do I get the photo names and captions into an array? The image names will already be set, and I'll already have an array from the photo upload. How do I add the captions to each photo in the array?
Thank you for your help! Any suggestions on doing it different are welcome'd!
Brandon
This is what I did:
Have index.html with the file upload
Goes to upload.php: Uploads the file and saves them into the user's folder (ex: brandon/photos/)
After upload completes, "echo" photos using "foreach" with a input "text" box. Each text box has the "name" of "captions[]" that builds an array of captions
On submission, goes to "addcaptions.php": Combines the files array and the captions array
addcaptions.php then adds, using "foreach", the photo filenames, the corresponding caption, and the username that corresponds to the photo to a MySql database using "mysqli"
And it works perfectly! All photos and captions are combined and ready to be used!
Thank you everyone for taking a look at this problem!
I have a project am working on,, its about (Graphical Password) it's an authentication security system (Web Based), which ask the user to register by entering his information such as (first name.. last name.. etc ) and with these information there will be a group of images with each image has a number written below it ,, so the user will enter his info like usually and will be an extra field for (image number) the user write the number of the image that he want ,,(the images will be previewed as thumbnails in the page). at the end he click submit, the information it will be stored in database using (PHPMyAdmin),in the database there will be columns for each data plus a column for image number, it will be storing the image number ONLY not the images, the images stored in a folder with its names from (1-20), till here no problem..
The Problem is : When the user click submit it should open another page and it should display the image that he chosen before from the previews page with big size image so later i can do some processing on the image..
My Question is : How to send that image to another page by using PHP language..
Am using DreamWeaver CS6, here is a photo of the site http://www.4shared.com/photo/YcBeAhsz/Capture.html?
and the code is here : http://www.4shared.com/file/unOI9Ejs/registeration_page.html?
I hope my question is clear and i wish i can get some answers.. thanks in advance..
This is a little tricky without know the code your using.
You can store the images you get to the web server by:
file_put_contents('image1.gif',file_get_contents('http://static.php.net/www.php.net/images/php.gif'));
The on the next page display the image back.
<?php
$user_picked_img_id = 1;
?>
<img src="image<?php echo $user_picked_img_id ?>.gif"/>
Let me know if that fits what you are trying to do.
i just wanna ask on how to make a simple gallery for my website wherein the images used to display are from database and will automatically display on the gallery? so that when i have to update the images i won't enormously create thumbnails..??
I would recommend against keeping the image data in a database, it's almost always a bad idea.
I would recommend storing metadata about the images in the database and then including a pointer to the file (the image's path on the local filesystem). If you need to make thumbnails create them as the images are added, store them on the filesystem too and store the path to them in the table too.
Another approach is to have the filename of the image and thumbnail as a function of the image ID. E.g. store it on the server at /some/directory/images/123.jpg and /some/directory/images/123_thumbnail.jpg where 123 is the id of the image.
use mysql BLOB storage - Example: http://www.anyexample.com/programming/php/php_mysql_example__image_gallery_%28blob_storage%29.xml
You can create the thumbnails and update the database when the images are uploaded to a directory within your http path. A simple php routine can extract the picture names from the db and include them in your gallery.
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.