Click to See Complete Forum and Search --> : About forms
Bashir
08-07-2008, 03:25 PM
Hello everyone,
I'm a new programmer in PHP and I have a question about forms.
I want to make a registration form includes the following items:
1-no (the number)
2-name
3-photo
4-tel (phone number)
5-address
6-email
The big problem is about how to add the photo to database and get it back in the view page later.
Please I need help if anyone knows.
Thank you
Yelgnidroc
08-07-2008, 04:59 PM
I dont add photos to databases, I store a reference to the photo within the database.
Quidam
08-07-2008, 05:04 PM
What Yelgnidroc said.
You can either make them include an url to the picture and save that url in the database, or you can make them upload the picture to your website and then store that url in the database.
pcthug
08-08-2008, 08:49 AM
Generally you will as previously discussed, allow the photo to be uploaded to your web server. It should be saved in a directory that can be publicly accessed (e.g; http://www.mysite.com/uploaded_photos/) and then save the uri of the photo (e.g; http://www.mysite.com/uploaded_photos/123456789.jpg) in the database. Then whenever you wish to display the image, just retrieve the photo uri and include it in your html.
Bashir
08-08-2008, 04:43 PM
Dear friends,
Thank you so much for this information, but I want to inform you that this form is a registration form, I mean when someone registers his information I want to view the information about him later (included the photo).If your answer is the only way to solve my problem that's OK and I will do it.
Thank you for your helping
FrankTheTank
08-08-2008, 05:49 PM
If your form uploads the photo and records the URL, then when you review it later, your view page should use that same image URL to load and display the image. Anyplace in the site that needs to display a users image should use this same URL field to do so.
Frank
Mr. E. Cryptic
08-08-2008, 06:41 PM
However, if you do want to store the image in a database and later retrieve it:
The file is called as any file upload would be;
$_FILES['UploadFieldName']['type'] //for the mmie type
$_FILES['UploadFieldName']['size'] //for the filesize in bytes
$_FILES['UploadFieldName']['name'] //for the file's name
To get the content of the file, you can use something like;
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
and add $content to your a blob in your DB.
Calling the image back takes a little more, first understand that you don't actually output the image to a page, instead; where you would normally have <img src="somePict.jpg"> you now use something like <img src="generateImage.php"> generateImage.php being a script that calls the data from the database, then set headers (for the image size, name etc.) and print (http://ie.php.net/manual/en/function.print.php) the content you've called from the database.
This tutorial (http://www.php-mysql-tutorial.com/php-mysql-upload.php) will get you on the right path. Be VERY careful, security wise, allowing files to be uploaded to a database.