| | |
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: 557
Reputation:
Solved Threads: 64
0
#2 Nov 12th, 2009
•
•
•
•
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
Views: 602 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for array, files, php, upload
2d access ajax array arrays asp autocomplete beginner buttons c# c++ char class cms curl data database date delete display downloader dropdownlist dynamic email file files flash flex form forms frequency function functions graph hosting html image include index input int integration java javascript jquery lamp limit link linux list listbox login mail menu methods multiple mysql news number object oop overwrite parse paypal pdf perl php pointer post problem programming query root saving script search security session sms soap spam sql storing stream string tutorial txt upload user validation variable variables vb vbulletin video web webdesign xml youtube zend






