Upload Images to database php - 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.

Related

Efficient way to upload images in a post for a blog?

I was wondering a method to upload images in the posts of a blog. I am thinking of two ways:-
1) To create a row in the database for imageurl and use this url to point to the image stored on the local disk.
2) Is there a way to upload images directly to mysql???
You could use BLOB to store image directly in your database, But it makes your database heavy and usually all hosting services put a limit on database sizes.
I faced the same issue a while back and after some research i found out that The best way is to store it your file system and store its url in your database.
If you only have one folder, you don't need to store the whole URL just the file name and append the domain when displaying it.
Hope its help. :)

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.

PyroCMS - Pyrostreams multiple file upload on one entry

I've got the PyroStreams module for PyroCMS and made a stream called portfolio. Everything is working as expected, however it only allows to upload just one image for my file field. That is obvious, but I'd like to know if there's a way to upload multiple images for one stream entry without adding x number of extra file fields. Or do I need to code an extra field type myself to support this? Maybe someone's got it already?
Thanks
According to me you have to create a separate database table that will hold all the images those are related to particular portfolio and the portfolio id by id by which you can fetch the images for particular record and then use any multiple image upload library like http://www.plupload.com/example_queuewidget.php to upload multiple images in the portfolio image table. Hopefully this will help you in achieving what you want.
There's a multi-upload files field type available on the pyrostore.

cakephp set field in this->data to a related field in database

I am trying to upload multiple images using meioupload which works fine if I set image.1.field and then image.2.field for each field of data. Then loop through and create/save rather than saveall.
My problem comes when I have field which is used as a subfolder for the image within an images folder.
for example I have a form
image.1.product id
image.1.artist
image.1.file to upload
image.2.product id
image.2.artist
image.1.file to upload
now when the items are saved, all data is correct including the belongsto relationship of product id, except the second image is stored in the wrong place.
The first image is stored in images / image.1.artist / file
the second image is stored in images / image.1.artist / image.2.artist / file
This is extremely annoying, and it is simply someting to do with the way the meioupload behaviour sets the subfolder to be a field from the array.
The way I have had to resort to saving the data is by looping through and creating then saving the values, which isnt a problem, but it obviously doesnt work with this method of setting a sub folder.
So a solution could possibly be to simply set the second artist field as blank and only add multiple images for the same artist..
Or to set the data field of artist to the actual field of artist in the related product the image will belong to, but I can't seem to get this to work?
So the question is how can I set the value of this field to the related products artist field that is already in the database for each seperate create/save?
ps. I am sorry if this is a bit long winded.
Right so the problem came because I was sending $this->data as 2 arrays. The solution was to read this->image->product->field('artist') and set it to this->data['Image'][1]['artist'].
This way it sets the field in the first array to artist, which in this particular meioupload behaviour will roll over to the second array of data and hence the image upload (which will then be suffixed with a /) This allows me to upload the images to their corresponding artist directory whilst creating 3 thumbnails and saving the relations, file info and so on.
I found that this doesn't seem to make a difference to loading the images (images work fine even though the display code effectively has two / in it, because the second image will be saved in the database as /dir/artist/ as a pose to the first one which is saved /dir/artist)
IF anyone has an ingenious way to call meioupload one at a time then this would hopefully avoid this slight issue, and then more and more images could be added into the same form..alas I am not clever enough to know how to do this yet..
Any help would be much appreciated!!!!

(php) - helping writing a script for uploading images

I am trying to upload an image to a directory on a server. i'm using the tutorial found at http://www.reconn.us/content/view/30/51/.
First, is that a good method for uploading images using PHP?
Second, I'm also going to store the info in a MySQL database. What is a good way to deal with images that have the same name that the user uploads? For example, if a user uploads a file 'test.png' 2x in a row, what should happen to the second filename? From the script above, both will get a unique filename, but how would I as the user access that image again? I couldn't just query because the only name I know was the duplicate name I gave it, and I definitely don't know the unique name the server gave it using the upload time...
Third, what is a good max file size for images?
You can report the unique URL back to the user after the upload so that the user will know where to find the image. So, the first test.png could be http://www.example.com/images/fjdklagjsdl.jpg and the second could be http://www.example.com/images/jklfsdlkj.jpg
You can also provide some kind of interface for users to view images they've uploaded. If you display a thumbnail of the uploaded image next to the image's unique filename, it will be easy for the user to identify which image is which.
This is the method I use:
Users upload images
Server saves the image with a unique (GUID or something) filename and stores - both - the unique generated filename and the original uploaded filename in a database
Images are linked to using either the original_filename, unique_filename or primary_key for the images table.
The images are taken from the server, and served using the original filename stored in the database. This way you avoid chances of conflicting filenames and you preserve the image's original filename. In addition, this allows you to build a search on the original_filename column for the user to use.
With this method, unique filenames never have to be exposed to the user, instead they're used to locate the image associated with a specific id or original_filename in the 'images` table.
Of course, if you don't care about giving the original filename to the image when it's displayed, you can just generate a unique filename whenever you want to store it.

Categories