I found this code on another forum and well I am trying I am having sql problems (which I know is a different subject and is already posted in the proper forum). What I am asking here is whether or not this php code is actually functional for what I am trying to do. $filename=($_FILES['filename']['name']); $filename2=($_FILES['filename2']['name']); $filename3=($_FILES['filename3']['name']); $filedescription1 = $_POST['filedescription1']; $filedescription2 = $_POST['filedescription2']; $filedescription3 = $_POST['filedescription3']; //This is the directory where images will be saved $target = "../photos/"; $targetx = $target . basename( $_FILES['filename']['name']); //Writes the photo to the server if(move_uploaded_file($_FILES['filename']['tmp_name'], $targetx)) { //Tells you if its all ok } else { //Gives and error if its not } $targetx = $target . basename( $_FILES['filename2']['name']); //Writes the photo to the server if(move_uploaded_file($_FILES['filename2']['tmp_name'], $targetx)) { //Tells you if its all ok } else { //Gives and error if its not } $targetx = $target . basename( $_FILES['filename3']['name']); //Writes the photo to the server if(move_uploaded_file($_FILES['filename3']['tmp_name'], $targetx)) { //Tells you if its all ok } else { //Gives and error if its not } PHP: Thank you for your advice in advance.
Assuming that the form you are posting to this from has all the inputs named properly, then this looks good to me.
The code looks good, but I would rename the files rather than using the existing file names. So you don't run into issues with overwriting files.
Yeah I need to add a renaming function; and a way to check for an empty upload variable to keep it from overwriting db data with empty fields. ( what I mean by this is that when i use a form to edit the db listing and leave the file upload field blank it overwrites the existing field data with the blank field info instead of leaving the existing info there if the field is left blank.) Been having trouble doing this...any ideas? Thanks for the help in advance.
Use this condition to check if the file field was empty: if ($_FILES['filename']['size'] > 0) { // File is full so do DB updates. } else { // File is empty so skip updates. } PHP: