FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File Upload Help
#1
For those who don't know - I just figured out why my upload was not working. Form Tools cannot create an file upload script for you - you have to do it yourself. First I made sure my server was configured for file uploads, and I had them add a tmp folder in the php ini settings. I dont know if that did anything but I will mention it anyway.

Now- I found a script online for file uploads and I adapted it to work with my form.

MAKE YOUR FORM START WITH THIS:

<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post" enctype="multipart/form-data">

INSTEAD OF THIS:

<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post">



Then add this below the submit button on your form:

<?php
if (isset($_POST['YOUR SUBMIT BUTTON NAME'])){

// Define the upload location
$target_path = "c:\\";

// Create the file name with path
$target_path = $target_path . basename( $_FILES['YOUR FILE FIELD NAME']['name']);

// Try to move the file from the temporay directory to the defined.
if(move_uploaded_file($_FILES['YOUR FILE FIELD NAME']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['YOUR FILE FIELD NAME']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>


Replace these values with your own:

YOUR FILE FIELD NAME
YOUR SUBMIT BUTTON NAME


That should make it so you can upload files with your own php form
Reply
#2
Will this work across multiple forms? Meaning, if my form has a second page and some of my uploads are on the first page and some on the second (which is my last page), will this allow me to save all that data at once. I remember it being a problem when trying to carry uploaded files in the SESSION or something like that. I had to resort to making a one page form that LOOKED like a two page form, kind of hackish and I didn't like it :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)