I am trying to upload files to my server using a flex program but the swf files are not being uploaded. So I tried to upload other file types such as png, jpg, txt, xml and all of these upload without a problem but swf will not upload.
MXML File:
<?xml version="1.0" encoding="utf-8"?>
private function init():void {
urlRequest = new URLRequest(serverSideScript);
fileReferenceList = new FileReferenceList();
fileReferenceList.addEventListener(Event.SELECT, fileSelectedHandler);
}
private function uploadFile():void {
fileReferenceList.browse();
}
private function fileSelectedHandler(event:Event):void {
var fileReference:FileReference;
var fileReferenceList:FileReferenceList = FileReferenceList(event.target);
var fileList:Array = fileReferenceList.fileList;
// get the first file that the user chose
fileReference = FileReference(fileList[0]);
// upload the file to the server side script
fileReference.addEventListener(Event.COMPLETE, uploadCompleteHandler);
fileReference.upload(urlRequest);
// update the status text
statusText.text = "Uploading...";
}
private function uploadCompleteHandler(event:Event):void {
statusText.text = "File Uploaded: " + event.target.name;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e开发者_C百科.g., services, value objects) here -->
</fx:Declarations>
<s:Label text="Upload File From Flex to PHP" fontWeight="bold"/>
<s:Label text="Choose a file..." id="statusText"/>
<s:Button click="uploadFile();" label="Upload File"/>
</s:Application>
PHP File:
<?php
$tempFile = $_FILES['Filedata']['tmp_name'];
$fileName = $_FILES['Filedata']['name'];
$fileSize = $_FILES['Filedata']['size'];
move_uploaded_file($tempFile, "./" . $fileName);
?>
I figured it out, it has nothing to do with flex at all. The problem that I was having is the max upload size in the php.ini file was set to 2mb and the file I was trying to upload was 5mb.
精彩评论