0 Replies Latest reply on Apr 26, 2006 7:32 PM by bob3546

    Uploading

    bob3546
      I have been trying for days to get this to work. I've used the help sample script, and I changed as much as I could find so that it would work with my website. I originally wanted to upload mp3s, but at this point I would be happy just to be able to upload images.

      Here is my PHP script:

      <?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;
      }
      }
      ?>
      ------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------


      ------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------
      Here is my actionscripting:
      ------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------


      ------------------------------------------------------------------------------------------ -------------------------------------------------------------------------------
      import flash.net.FileReference;

      imagePane.setSize(400, 350);
      imagePane.move(75, 25);
      uploadBtn.move(75, 390);
      uploadBtn.label = "Upload Image";
      imageLbl.move(75, 430);
      imageLbl.text = "Select Image";
      statusLbl.move(210, 390);
      statusLbl.text = "Status";
      imagesCb.move(75, 450);
      statusArea.setSize(250, 100);
      statusArea.move(210, 410);

      /* The listener object listens for FileReference events. */
      var listener bject = new Object();

      /* When the user selects a file, the onSelect() method is called, and passed a reference to the FileReference object. */
      listener.onSelect = function(selectedFile:FileReference):Void {
      /* Update the TextArea to notify the user that Flash is attempting to upload the image. */
      statusArea.text += "Attempting to upload " + selectedFile.name + "\n";
      /* Upload the file to the PHP script on the server. */
      selectedFile.upload(" http://www.kittenclub.org/TomStuff/uploadFile.php");
      };

      /* When the file begins to upload, the onOpen() method is called, so notify the user that the file is starting to upload. */
      listener.onOpen = function(selectedFile:FileReference):Void {
      statusArea.text += "Opening " + selectedFile.name + "\n";
      };

      /* When the file has uploaded, the onComplete() method is called. */
      listener.onComplete = function(selectedFile:FileReference):Void {
      /* Notify the user that Flash is starting to download the image. */
      statusArea.text += "Downloading " + selectedFile.name + " to player\n";
      /* Add the image to the ComboBox component. */
      imagesCb.addItem(selectedFile.name);
      /* Set the selected index of the ComboBox to that of the most recently added image. */
      imagesCb.selectedIndex = imagesCb.length - 1;
      /* Call the custom downloadImage() function. */
      downloadImage();
      };

      var imageFile:FileReference = new FileReference();
      imageFile.addListener(listener);

      imagePane.addEventListener("complete", imageDownloaded);
      imagesCb.addEventListener("change", downloadImage);
      uploadBtn.addEventListener("click", uploadImage);

      /* If the image does not download, the event object's total property will equal -1. In that case, display a message to the user. */
      function imageDownloaded(event bject):Void {
      if (event.total == -1) {
      imagePane.contentPath = "Message";
      }
      }

      /* When the user selects an image from the ComboBox, or when the downloadImage() function is called directly from the listener.onComplete() method, the downloadImage() function sets the contentPath of the ScrollPane in order to start downloading the image to the player. */
      function downloadImage(event bject):Void {
      imagePane.contentPath = " http://www.kittenclub.org/TomStuff/images/" + imagesCb.value;
      }

      /* When the user clicks the button, Flash calls the uploadImage() function, and it opens a file browser dialog box. */
      function uploadImage(event bject):Void {
      imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
      }




      Please Help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      PS: Sorry about all of the smiley faces....