uploading a file
Posted: Mon Nov 07, 2011 3:14 am
Hi, really need some extra brains to help me with this one!
I have a form with only 1 text box (input type=text)
in this textbox I enter a local path on my computer to a specific folder. in this folder I have few files, each has a set name that I know in advance.
what I want to do is to be able to upload all those files in my local folder to the server, without making the user click browes and pick them 1 by 1.
I searched and searched but I see it's not as simple as I thought cuz I can't just set the value of the input file..
since my page has a form eitherway I thought of maybe doing something sneaky and hiding the input files and some how passing them the path of each file (the folder path will be taken from the not hidden textbox) and the file name is known to me so I can add those 2 somehow..
I can't find a way to do that, so I wonder if any of you have an idea? maybe it's possible to set the file path after the form is submited? basicly I think it's possible to give the name of the file, but I also need the temp name of the file ($_FILES['docfile1']['tmp_name']), and this I don't know how to set..
this is my code for uploading a file with <input type=file>
desperately need help!
I have a form with only 1 text box (input type=text)
in this textbox I enter a local path on my computer to a specific folder. in this folder I have few files, each has a set name that I know in advance.
what I want to do is to be able to upload all those files in my local folder to the server, without making the user click browes and pick them 1 by 1.
I searched and searched but I see it's not as simple as I thought cuz I can't just set the value of the input file..
since my page has a form eitherway I thought of maybe doing something sneaky and hiding the input files and some how passing them the path of each file (the folder path will be taken from the not hidden textbox) and the file name is known to me so I can add those 2 somehow..
I can't find a way to do that, so I wonder if any of you have an idea? maybe it's possible to set the file path after the form is submited? basicly I think it's possible to give the name of the file, but I also need the temp name of the file ($_FILES['docfile1']['tmp_name']), and this I don't know how to set..
this is my code for uploading a file with <input type=file>
Code: Select all
if ($_FILES['docfile1']['name']!='') {
$target = 'import/';
$target = $target . basename($_FILES['docfile1']['name']);
if ($target =="import/myfile.xlsx"){
if (file_exists($target))
unlink($target);
if (move_uploaded_file($_FILES['docfile1']['tmp_name'], $target)) {
echo 'success';
}else{
echo 'fail';
}
}else{
echo 'fail';
}
}