uploading a file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
54uydf
Forum Newbie
Posts: 4
Joined: Mon Nov 07, 2011 3:09 am

uploading a file

Post by 54uydf »

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>

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'; 	
    }
}
desperately need help!
54uydf
Forum Newbie
Posts: 4
Joined: Mon Nov 07, 2011 3:09 am

Re: uploading a file

Post by 54uydf »

ok I see not much is happening..
maybe anybody knows of a solution I can use that is not in PHP?
is it really impossible to upload multiple files without selecting each one of them 1 by 1??
mikeashfield
Forum Contributor
Posts: 159
Joined: Sat Oct 22, 2011 10:50 am

Re: uploading a file

Post by mikeashfield »

54uydf
Forum Newbie
Posts: 4
Joined: Mon Nov 07, 2011 3:09 am

Re: uploading a file

Post by 54uydf »

I saw an array and my eyes went like this 8O lol but I see it still requiers the user to chose each file separately :?
not what I'm looking for..
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: uploading a file

Post by Celauran »

54uydf wrote:is it really impossible to upload multiple files without selecting each one of them 1 by 1??
As far as I can tell, yes. HTML 5 supports the multiple attribute, which allows you to select multiple files (except in IE, of course) but only one seems to get uploaded.
54uydf
Forum Newbie
Posts: 4
Joined: Mon Nov 07, 2011 3:09 am

Re: uploading a file

Post by 54uydf »

lol IE is kinda important haha, but wow if there was like a simple setting I could change on this standard input file I think I might have saved myself 2 months of headache of trying to find ather solutions..
can't believe such basic thing isn't available with a simple tag.. :crazy:
Post Reply