Jump to content

File Upload among a regular form possible?


PupChow

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!
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.