| | |
Upload file using array for files
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Solved Threads: 0
Hi,
I am reading in a bunch of files to upload but they are in an array:
To upload the files I call a function uploadFile() which looks like this:
The only problem is when I get the files from the form, they are in an array and I can't seem to point the correct string to the upload file function.
Thanks!
I am reading in a bunch of files to upload but they are in an array:
PHP Syntax (Toggle Plain Text)
<input id="tab1file0" class="tab1Files files" type="file" name="tab1file[]" /> <input id="tab1file1" class="tab1Files files" type="file" name="tab1file[]" />
To upload the files I call a function uploadFile() which looks like this:
PHP Syntax (Toggle Plain Text)
function uploadFile($thefile) { $base_path = "files/"; $target_path = $base_path . basename( $_FILES[$thefile]['name']); echo($_FILES[$thefile]['tmp_name']); if(move_uploaded_file($_FILES[$thefile]['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES[$thefile]['name'])." has been uploaded <br>"; } else{ echo "There was an error uploading the file".basename( $_FILES[$thefile]['name']).", please try again!<br>"; } }
The only problem is when I get the files from the form, they are in an array and I can't seem to point the correct string to the upload file function.
Thanks!
•
•
Join Date: Sep 2009
Posts: 525
Reputation:
Solved Threads: 61
0
#2 18 Days Ago
•
•
•
•
Hi,
I am reading in a bunch of files to upload but they are in an array:
PHP Syntax (Toggle Plain Text)
<input id="tab1file0" class="tab1Files files" type="file" name="tab1file[]" /> <input id="tab1file1" class="tab1Files files" type="file" name="tab1file[]" />
To upload the files I call a function uploadFile() which looks like this:
PHP Syntax (Toggle Plain Text)
function uploadFile($thefile) { $base_path = "files/"; $target_path = $base_path . basename( $_FILES[$thefile]['name']); echo($_FILES[$thefile]['tmp_name']); if(move_uploaded_file($_FILES[$thefile]['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES[$thefile]['name'])." has been uploaded <br>"; } else{ echo "There was an error uploading the file".basename( $_FILES[$thefile]['name']).", please try again!<br>"; } }
The only problem is when I get the files from the form, they are in an array and I can't seem to point the correct string to the upload file function.
Thanks!
PHP Syntax (Toggle Plain Text)
extract($_POST); foreach($tab1file as $key=>$value) { //call your function here }
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
![]() |
Similar Threads
- Upload all the file in a folder to Server using JavaScript / web service (JavaScript / DHTML / AJAX)
- file upload script for music files and video files (PHP)
- Upload a file to a ftp server using delphi (Pascal and Delphi)
- Upload File Through Forum (PHP)
- Upload problem of large files in Win 2003 (Windows NT / 2000 / XP)
- validate-upload file (ASP.NET)
- Working with array of files (C++)
- array of files in C (C)
Other Threads in the PHP Forum
- Previous Thread: Need help building an instant messaging system with AJAX/PHP
- Next Thread: Javascript not working in PHP class file
| Thread Tools | Search this Thread |
access ajax ajaxcode array autocomplete basic beginner broken buttons c# c++ char class cms curl data database delete developers display dropdown dropdownlist dynamic email file files flash flex form forms frequency function functions gentoo graph hosting html image include index insert int java javascript jquery lamp limit link list listbox login mail menu methods multiple mysql news number oop parse pdf perl php pointer post problem programming query random remove root script search security session sms source spam split sql string support! survey trouble tutorial txt update upload users variable variables vb video virus web webdesign website websitecontactform youtube zend






