Facebook style- Adding captions to photos - php

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!

Related

Upload Images to database php

I have a doubt..
I´m doing in php a page to buy and sell cars, and I have a form that has 5 input files(one for each image). The question is: Do I have to do 5 times the same file to upload each image separately or with one file that executes the code for the 5 images it´s ok?
You can assign each files with an id from 1-5. Like this $_FILES['filename']['#id'] and then use a for loop to upload them from 1-5. Hope this helps. There is a similar question here. Multiple image upload using php
As smuhero has said above, but you could also edit your database to have 5 seperate fields (one for each picture) then if a picture is uploaded you could either store the image directly in the database (takes a lot of space as you have to convert the image to Base64 data and then insert) or leave the location of the picture in the field.
Of course you'd have to ensure that you securely protect against incorrect files being called by malicious users.

change position of image in image gallery using php

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/

Open php page in Fancybox, lightbox etc on form submit

I have a user profile page and want to allow the user to do the following:
Click 'CHANGE AVATAR'
Select new pic and upload it
Pic shows in lightbox (of some sort)
Allow the user to use jcrop to crop image
Save cropped image in user folder
I can achieve the upload part and know how to use php to save a file to user folder and add filename to the users row in mysql table for avatar.
I can find no tutorials to show me how to open the image in a lightbox ad enable the user to edit with jcrop.
I figure I will have to:
post the uploaded filename to a php file (ajax?)
include the php file in an iframe to use with fancybox (or alternative)
echo the uploaded image and initialize jcrop within the php file for the shown image
Save the image with random filename using php
I am stuck with points 2-4 on the last list. Please help...
Can nobody seriously help me with this??

Upload image and associate it with row on database

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>);

How to send an image from one page to another page using PHP

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.

Categories