Hi !
I'm a php developer.
I'm developing a site into which I have to upload a text file and a image file
from users through a browse box and then I have to retrieve that file and save it
into mysql database .Should I use POST method to retrieve the browse box
value that have been uploaded with a text file or image file.For example :-
<html>
<body>
<form method="post" action="test.php">
<input type="file" name="file_read" id="file_read">
<?php
$temp_var=$_POST["file_read"];
?>
</form>
</body>
</html>
Hi!
I dont understand why you would wanna browse later andd do such gimmicks. Further, once the user on your site uploaded and image and when the image is in your server directory, how would you know that this is the image that belongs to him and this would post serious problems when you were to have several users. If however you have to do it this way, then I suggest that when you get the image filename while it is uploaded, concatenate the filename with the user name. But this is such an inconvinient tech.
A simplsitic approach would be to have a field named image (say) in your database. Now when the user uploads a file, get the filename using php fuctions. and then perform a simple query.
could be like
INSERT INTO db.table_name(name,image) VALUES ('name','file_name' )
So then this is an easier way.
In this way, you have the user's name and the name of the file the user has uploaded. Thereby whenever you wanna open/use this file, you can use the name of the file stored in the image field of your database. This file name / image name now points to that file located on your server directory. thereby when you say something like <img src="<?php echo $image_name?>">, this would actually query the database fetch that image name which actually points to the file / image in your server directory.
Now lets assume the user registers first wand wants to upload an image later,
the the query would be: (Assuming there is an option to upload later)
UPDATE db.table_name SET image='file_name' WHERE name = 'person_already_registered_but_uploading_now';
Hope I am op help to you.
CyberKing
http://www.bytesandbytes.com