Jump to content


Photo

File Upload among a regular form possible?


  • Please log in to reply
2 replies to this topic

#1 PupChow

PupChow
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 March 2006 - 05:05 AM

As a part of the form, I am hoping to have an Upload Picture section where it lets the user browse his/her computer and upload a file onto the server. At which point the server will resize the image, move it to a sepecific folder, rename it, and write the new name in a MySQL database.

The way I have my form setup right nowis that once a form is submitted, the page is reloaded with all the INSERT SQL statements being executed. Is it possible to mix a file upload in the same form?

Thanks, I would like to know if this is possible first before investing hours into development!

#2 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 19 March 2006 - 08:28 AM

yes you can i is fairly simple
// place your query here
mysql_query("your Query") or die ("could not query");

//and place your upload code here 
$pic=$_POST['file_to_upload'];

move_to_upload("$pic") 
$upload_dir="dir/";
yada
yada
yada



placeing it this way if the query fails it may not upload the pic(i am not sure it might upload the pic) you can reverse it and place the upload code at the top and the query at the bottom but the down fall of doing it the way is the pic will upload first then the query will run and if the query fails you will have a pic but you wont have the users info that goes with the pic

or you can do it ths way

doing the code this way is probably the smartest way to do it because if the query works or inserts into the db it will call for the upload cod to run and if the query fails it tells oy uit failed and stops the upload from happening


/ place your query here
$sql=mysql_query("your Query") 
if(!$sql){
echo "Could not query";
}
else
{

//and place your upload code here 
$pic=$_POST['file_to_upload'];

move_to_upload("$pic") 
$upload_dir="dir/";
yada
yada
yada

}



i hope this is what you are looking for and works for you if not sorry in advance
The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#3 PupChow

PupChow
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 19 March 2006 - 02:09 PM

Perfect, exactly what I needed to know! I will play with this today, thanks a lot!!! :)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users