Hi all

Now I`m trying to make file upload process.

This is my code (down below)

-------------- Flex Code -------------

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";>
<mx:Script>
        <![CDATA[

import flash.net.FileFilter;
import flash.net.FileReference;
import flash.net.URLRequest;

public var imageTypes:FileFilter = new FileFilter("Images (*.jpg, 
*jpeg, *.gif, *.png)","*.jpg; *jpeg; *.gif; *.png");

public var textTypes:FileFilter = new FileFilter("Text Files (*.txt, 
*rtf)","*.txt; *.rtf");

public var allTypes:Array = new Array(imageTypes, textTypes);
public var myFileRef:FileReference = new FileReference();
            
public function initApplication(): void
{
myFileRef.addEventListener(Event.SELECT, selectHandler);
myFileRef.addEventListener(Event.COMPLETE, completeHandler);
myFileRef.browse(allTypes);
  try {
        var success:Boolean = myFileRef.browse();
            } catch (error:Error) {
                 trace("unable to browse for files");
            }
            
          function selectHandler (even:Event):void 
            {
                try {
                   var params:URLVariables = new URLVariables();
                    params.date = new Date();
                    var request:URLRequest = new URLRequest
("http://myserver/upload.php";);
                    request.method = URLRequestMethod.POST;
                     request.data = params;
                      myFileRef.upload(request, "fileField");
                    } catch (error:Error) {
                        trace("Unable to upload file");
                    }
                }
            
                function completeHandler(event:Event):void
                {
                    trace("Uploaded");
                }
            }

        ]]>
</mx:Script>
        

    <mx:Button label="Local File" click="initApplication();"/>
    
</mx:Application>



------------- upload.php (I just copy from Adobe example)-----------
<?php
$MAXIMUM_FILESIZE = 1024 * 200; // 200KB
$MAXIMUM_FILE_COUNT = 10; // keep maximum 10 files on server
echo exif_imagetype($_FILES['Filedata']);
if ($_FILES['Filedata']['size'] <= $MAXIMUM_FILESIZE) {
  move_uploaded_file($_FILES['Filedata']
['tmp_name'], "./temporary/".$_FILES['Filedata']['name']);
  $type = exif_imagetype("./temporary/".$_FILES['Filedata']['name']);
  if ($type == 1 || $type == 2 || $type == 3) {
    rename("./temporary/".$_FILES['Filedata']
['name'], "./images/".$_FILES['Filedata']['name']);
  } else {
    unlink("./temporary/".$_FILES['Filedata']['name']);
  }
}
$directory = opendir('./images/');
$files = array();
while ($file = readdir($directory)) {
  array_push($files, array('./images/'.$file, filectime
('./images/'.$file)));
}
usort($files, sorter);
if (count($files) > $MAXIMUM_FILE_COUNT) {
  $files_to_delete = array_splice($files, 0, count($files) - 
$MAXIMUM_FILE_COUNT);
  for ($i = 0; $i < count($files_to_delete); $i++) {
    unlink($files_to_delete[$i][0]);
  }
}
print_r($files);
closedir($directory);

function sorter($a, $b) {
  if ($a[1] == $b[1]) {
    return 0;
  } else {
    return ($a[1] < $b[1]) ? -1 : 1;
  }
}
?>

--------------------Apache Log-----------------------

PHP Notice:  Undefined index:  Filedata in /usr/local/apache-tomcat-
5.5.17/webapps/ROOT/upload.php on line 4
PHP Notice:  Undefined index:  Filedata in /usr/local/apache-tomcat-
5.5.17/webapps/ROOT/upload.php on line 5
PHP Notice:  Undefined index:  Filedata in /usr/local/apache-tomcat-
5.5.17/webapps/ROOT/upload.php on line 6
PHP Notice:  Undefined index:  Filedata in /usr/local/apache-tomcat-
5.5.17/webapps/ROOT/upload.php on line 6
PHP Notice:  Undefined index:  Filedata in /usr/local/apache-tomcat-
5.5.17/webapps/ROOT/upload.php on line 7
PHP Warning:  exif_imagetype(): Read error! in /usr/local/apache-
tomcat-5.5.17/webapps/ROOT/upload.php on line 7
PHP Notice:  Undefined index:  Filedata in /usr/local/apache-tomcat-
5.5.17/webapps/ROOT/upload.php on line 11
PHP Warning:  unlink(./temporary/): Is a directory 
in /usr/local/apache-tomcat-5.5.17/webapps/ROOT/upload.php on line 11
PHP Notice:  Use of undefined constant sorter - assumed 'sorter' 
in /usr/local/apache-tomcat-5.5.17/webapps/ROOT/upload.php on line 19



upload brower is look`s like working aright. 
what did I miss? 

Thanks,
Jay


Reply via email to