Jump to content

Archived

This topic is now archived and is closed to further replies.

PupChow

File Upload among a regular form possible?

Recommended Posts

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!

Share this post


Link to post
Share on other sites
yes you can i is fairly simple
[code]
// 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


[/code]

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

[code]

/ 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

}


[/code]

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

Share this post


Link to post
Share on other sites
Perfect, exactly what I needed to know! I will play with this today, thanks a lot!!! :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.