0

I'm trying to upload file using flash So

I've following code in action-script:

var fileRef:FileReferenceList = new FileReferenceList();
fileRef = new FileReferenceList();
fileRef.browse(new Array( new FileFilter( "Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg;*.jpeg;*.gif;*.png" )));
fileRef.addEventListener(Event.SELECT, fileSelectHandler);

var uploadURL:URLRequest = new URLRequest();
var uploadPhotoScript:String = "http://localhost/uploader/upload.php";
uploadURL.url = uploadPhotoScript;

function fileSelectHandler(event:Event):void {
    for each(var fileToUpload:FileReference in fileRef.fileList){
            uploadSingleFile(fileToUpload);
        }
}

function uploadSingleFile(file:FileReference):void {
file.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
file.upload(uploadURL);
file.addEventListener(Event.COMPLETE, completeHandler);
}

function onUploadProgress(e:ProgressEvent):void
{
    var f:FileReference = e.currentTarget as FileReference;
    var fileName:String = f.name; //Now I know which file it is, I can update accordingly
    var progress:Number = (e.bytesLoaded / e.bytesTotal) * 100; //shows percent, you might want to round this off using Math.round(number);
}

function completeHandler(event:Event):void {
    trace("upload complete");
}

upload.php:

<?php
if(isset($_SERVER["HTTP_REFERER"]){
  $ref=$_SERVER["HTTP_REFERER"];
  $ref=explode($ref,"/");
  $ref=$ref[2];
   if($ref=="localhost"){
     if(!empty($_FILES)){
        $tmpfile = $_FILES['Filedata']['tmp_name'];
        $targetfile = dirname(__FILE__) . '/' . $_FILES['Filedata']['name'];
       move_uploaded_file($tmpfile, $targetfile);
     }
  }
else{
header("location:NotLocalhost.html");
exit;
}
}
else{
header("Location:NOREF.html");
exit;
}
?>

This code works fine in all browsers except firefox. coz In firefox $_SERVER["HTTP_REFRER"] becomes null and NOREF.html is displayed.

Also in firefox when the script is accessed by another html or php script then works fine, but when is accessed vai swf movie which is in turn <embeded> in html page. Then the REFERER becomes null.

Any ideas? How can I solve this?

Vedant Terkar
  • 4,553
  • 8
  • 36
  • 62

0 Answers0