0 Replies Latest reply on Mar 8, 2008 7:30 AM by thejokerman05

    Shouldn't this work?

    thejokerman05
      I want to upload the files in the folder on server which the user selected in the ComboBox. But I cant get it working, any ideas?

      In Flex:
      private function startUpload():void {
      if (_arrUploadFiles.length > 0) {
      disableUI();

      listFiles.selectedIndex = _numCurrentUpload;
      scrollFiles();

      // Variables to send along with upload
      var sendVars:URLVariables = new URLVariables();
      sendVars.projekt = ComboBox(projektNamn).selectedItem.data;

      var request:URLRequest = new URLRequest();
      request.data = sendVars;
      request.url = _strUploadUrl;
      request.method = URLRequestMethod.POST;
      _refUploadFile = new FileReference();
      _refUploadFile = listFiles.selectedItem.file;
      _refUploadFile.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);
      _refUploadFile.addEventListener(Event.COMPLETE, onUploadComplete);
      _refUploadFile.addEventListener(IOErrorEvent.IO_ERROR, onUploadIoError);
      _refUploadFile.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onUploadSecurityError);
      _refUploadFile.upload(request, "file", false);
      }
      }

      This in upload.php:
      $file_path = $_SERVER['DOCUMENT_ROOT']."/mockingbird/".$_REQUEST['projekt'];

      $file_temp = $_FILES['file']['tmp_name'];
      $file_name = $_FILES['file']['name'];

      //checks for duplicate files
      if (!file_exists($file_path."/".$file_name)) {

      //complete upload
      $filestatus = move_uploaded_file($file_temp,$file_path."/".$file_name);

      if(!$filestatus) {
      $success = "false";
      array_push($errors,"Upload failed. Please try again.");
      }
      }

      else {
      $success = "false";
      array_push($errors,"File already exists on server.");
      }

      break;

      default:
      $success = "false";
      array_push($errors,"No action was requested.");

      }

      return_result($success,$errors,$data);