A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: [Resolved] [Resolved] File not uploading :(

Threaded View

  1. #1
    Senior Member Vincent26381's Avatar
    Join Date
    Feb 2003
    Location
    The Netherlands
    Posts
    833

    File not uploading :(

    Hi,

    I used a script found on this forum for uploading files. On itself it works fine but when I added it to my script it doesn't work

    This script is to play a game with a local file. That all work ok but I also want the viewer to be able to send it to a friend. My thought was to upload the local file to a folder on the server, make a link from the filename to tell Flash what to load.

    The link
    (try a .jpg file on your harddisk)

    This is the PHP script (please excuse my n00bisch scripting)

    PHP Code:
    <?
    // unique id should go here to upload and pass to flash
    $picture = $userfile;
    $maxbytes = 400000; // if you change this and the next line,
    $maxbytesk = "400k"; // make the same changes in the html file
    $uploaddir = '/opt/guide/www.avviso.nl/HTML/jer/photo/'; //change this to the correct destination folder
    $unique_id = date("m-d-y"); //date is put in the filename to help keep it unique

    // Javascript seems to handle strings different from Flash:
    $pic = urlencode($picture);
    $pictureNew = addslashes ($picture);
    if ($pic == ""){
    print '<HTML><HEAD><TITLE>submit your file</TITLE>';

    print '
    <SCRIPT LANGUAGE=JavaScript>';
    print '
    function upload(){';
    print '
    }';
    print '
    </SCRIPT>';
    print'
    <body bgcolor="#000000"><center><form method="';
    echo $_SERVER['DOCUMENT_ROOT']; 
    echo $_SERVER['PHP_SELF']; 
    print '">
    <p><input type="file" name="userfile" size="20"><input type="submit" value="Submit" name="B1"></p>
    <input type="hidden" name="MAX_FILE_SIZE" value="400000">
    </form>
    <BR><BR>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
      codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0"
      id="uploadpic" width="400" height="400">
      <param name="movie" value="uploadpic.swf">
      <param name="quality" value="high">
      <param name="bgcolor" value="#000000">
        <embed name="uploadpic" src="uploadpic.swf"
         quality="high" bgcolor="#000000" swLiveConnect="true"
         width="400" height="400"
         type="application/x-shockwave-flash"
         pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
    </object>
    </center>
    </BODY>
    </HTML>';
    // start file upload here
    } else {
    print '<HTML><HEAD><TITLE>submit your file</TITLE>';
    print '
    <SCRIPT LANGUAGE=JavaScript>';
    print '
    function upload(){';
    print '
    window.document.uploadpic.SetVariable("pic", ';
    print '"' . $pictureNew . '"';
    print ');';
    print '
    }';
    print '
    </SCRIPT>';
    print '
    <body bgcolor="#000000"><center>  
    <form method="';
    echo $_SERVER['DOCUMENT_ROOT']; 
    echo $_SERVER['PHP_SELF']; 
    print '">
    <p><input type="file" name="userfile" size="20"><input type="submit" value="Submit" name="B1"></p>
    <input type="hidden" name="MAX_FILE_SIZE" value="400000">
    </form>
    <BR><BR>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
      codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,79,0"
      id="uploadpic" width="400" height="400">
      <param name="movie" value="uploadpic.swf">
      <param name="quality" value="high">
      <param name="bgcolor" value="#000000">
        <embed name="uploadpic" src="uploadpic.swf"
         quality="high" bgcolor="#000000" swLiveConnect="true"
         width="400" height="400"
         type="application/x-shockwave-flash"
         pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
    </object>
    </center>
    </BODY>
    </HTML>';
    }
    $imgarray = array("image/pjpeg", "image/jpeg", "image/gif", "image/png", "image/x-png", "text/txt", "text/doc", "sheet/xls", "slideshow/ppt");
    $filetype = $_FILES['userfile']['type'];
    $filename = $_FILES['userfile']['name'];
    $filesize = $_FILES['userfile']['size'];
    $newfilename = $unique_id."_".$_FILES['userfile']['name'];
    //Note: if filesize excededs the limit in html file, the browser will terminate the upload
    //and return a length of 0 bytes.
    if ($filesize==0){
    echo "Het bestand heeft een ongeldige naam, bevat 0 bytes of overschreed $maxbytesk bytes";
    }else if ($filesize > $maxbytes) {
    echo "Het bestand overschreed de $maxbytesk bytes";
    exit;
    }else if (!in_array($filetype,$imgarray)){
    }
    print "<pre>";
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $newfilename)) {
    print "nieuwe bestandsnaam:\n\n";
    echo "$newfilename\n\n";
    } else {
    print "File was not uploaded!\n";

    }
    ?>
    Any ideas why the script doesn't upload the file?

    I would be extremely gratefull

    Vincent
    Last edited by Vincent26381; 08-28-2003 at 10:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center