Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //start a PHP session.
- session_start();
- class Upload {
- //upload directory.
- //make sure it exists
- //chmod it to 0777 to be writable
- var $upload_dir = "uploads/";
- //the name of the file.
- var $name = '';
- //TMP name of the file on server.
- var $tmp_name = '';
- //the size of the file.
- //this is measured in bytes
- var $size = '';
- //the mime type of the file.
- //ex. image/png
- var $type = '';
- //number of files uploaded so far.
- var $count = 1;
- function Upload($file = array()) {
- //make sure that the file data is not empty.
- if (!empty($file)) {
- //loop the file array
- foreach ($file as $key => $val) {
- $this -> {$key} = $val;
- }
- //execute the uploading method.
- $this -> upload_file();
- }
- }
- function upload_file() {
- //make sure the the file has been uploaded
- if (is_uploaded_file($this -> tmp_name)) {
- //make sure that the file can be moved to the "upload_dir"
- if (move_uploaded_file($this -> tmp_name, $this -> upload_dir . $this -> name)) {
- //increment the file count.
- $newcount = (!isset($_SESSION['filecount'])) ? $this -> count : ($_SESSION['filecount'] + 1);
- $_SESSION['files'][$newcount]['filename'] = $this -> name;
- $_SESSION['files'][$newcount]['filesize'] = $this -> size;
- $_SESSION['files'][$newcount]['filetype'] = $this -> type;
- } else {
- //file could not be moved
- return false;
- }
- } else {
- //file was not uploaded
- return false;
- }
- }
- }
- //get all the posted file data
- $file = $_FILES['Filedata'];
- //initialize the Upload class.
- $upload = new Upload($file);
- ?>
- <?php
- //custom variable passed to the flash application
- $customVariable = $_GET['customVariable'];
- //the number of files uploaded
- $totalFileCount = $_GET['totalFileCount'];
- //loop the uploaded files.
- //this is received from the flash application
- for ($i = 0; $i < $totalFileCount; $i++) {
- $files[$i] = array(
- 'filename' => $_GET['filename' . $i],
- 'filesize' => $_GET['filesize' . $i],
- 'filetype' => $_GET['filetype' . $i],
- );
- }
- //appand some text to our data.
- $data = "Custom Variable - " . $customVariable . "\n";
- $data .= "Total File Count - " . $totalFileCount . "\n";
- foreach ($files as $fKey => $fVal) {
- foreach ($files[$fKey] as $fKey2 => $fVal2) {
- $data .= $fKey2 . " no " . $fKey . " - " . $fVal2 . "\n";
- }
- }
- //open a new log file.
- $fh = fopen("uploads/test_" . time() . ".txt", "w");
- //write the generated data to the file.
- fwrite($fh, $data);
- //close the log file handle
- fclose($fh);
- //response for the flash application
- echo 'success';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement