| | |
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: 539
Reputation:
Solved Threads: 63
0
#2 22 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 array arrays asp beginner buttons c# c++ cast char character class cms code curl data database delete display dropdown dynamic eclipse email file files flash form forms frequency function graph href html image include index input integration java javascript jquery lamp limit link list listbox login mail menu multiple multipletables mysql mysqlquery news number oop paypal pdf perl persist php pointer post problem programming provider query remote ruby script search security session sms soap sockets source spam sql string subdomain tag traffic tutorial update upload user validation variable vb video virus web webbrowser webdesign website xml youtube zend






