Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

code sample of oncomplete code
  • Hey Im not very good at JavaScript and just needed to know where i put the on complete all with the filepath.


    $(document).ready(function() {
    $("#fileUpload").fileUpload({
    'uploader': 'uploader.swf',
    'cancelImg': 'images/cancel.png',
    'folder': 'uploads',
    'script': 'upload.php',
    'buttonText': 'Select File',
    'displayData': 'percentage',
    onAllComplete: function() {
    fileObj:filepath();
    }


    });

    I do not know if this is right couple someone point me in the right direction. I want to be able to have the url path to the file show up as soon as the file has uploaded so that users are able to go to that url and download the file that has been stored or be able to share it with other people. Please tell me if u need any more info?
  • You want onComplete not onAllComplete

    onComplete: function(event, queueID, fileObj, reposnse, data) {
    $('#filesUploaded').append('<a href='+fileObj.filePath+'>'+fileObj.name+'</a><br>');
    }

    then in your html add the div
    <div id=\"filesUploaded\"></div>

    All uploads will then create a link and place it within the specified div.
  • Hey thank you so much that was great but....I have changed the name of the file while processing the file in upload the php, it doesnt come back with the renamed file which is useless because i will not be able to download the file. Are there any ways around this??
  • echo the new name in the upload script. Then you can use response in the onComplete override. Look at the scriptData sample for more info.
  • I have tried putting echo and it still does not give me the url of the renamed file. Heres the code i am using in my upload.php

    <?php
    // Uploadify v1.6.2
    // Copyright (C) 2009 by Ronnie Garcia
    // Co-developed by Travis Nickels
    include \"config.php\";
    if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';

    $ext = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION); //figures out the extension

    $newFileName = md5($tempFile).'.'.$ext; //generates random filename, then adds the file extension
    $targetFile = str_replace('//','/',$targetPath) . $newFileName;

    move_uploaded_file($tempFile,$targetFile);

    echo $newFileName;
    else // Required to trigger onComplete function on Mac OSX
    echo '1';

    }

    ?>


    and that is the only way it will upload and rename
    but then when it comes back it comes back as the original named file url.

    My javascript/flash is

    <script type=\"text/javascript\" src=\"javascript/jquery.js\"></script>
    <script type=\"text/javascript\" src=\"javascript/jquery.uploadify.js\"></script>
    <script type=\"text/javascript\">
    $(document).ready(function() {
    $(\"#fileUpload\").fileUpload({
    'uploader': 'uploader.swf',
    'cancelImg': 'images/cancel.png',
    'folder': 'uploads',
    'script': 'upload.php',
    'buttonText': 'Select File',
    'displayData': 'percentage',
    'onComplete': function(event, queueID, fileObj, reposnse, data) {
    $('#filesUploaded').append('<a href='+fileObj.filePath+'>'+fileObj.name+'</a><br>');
    }


    });

    });
    </script>


    and here is my form

    <h2>Upload Files</h2>
    <form>
    <p>
    <input name=\"fileUpload\" id=\"fileUpload\" type=\"file\" />
    <a href=\"javascript:$('#fileUpload').fileUploadStart()\">Start Upload</a></p>
    <div id=\"filesUploaded\"></div>
    <p>&amp;nbsp;</p>
    </form>
    </body>


    do you think theres something wrong with the form because i have done everything u said and still no renamed file sent back?
  • Your not pulling the echoed data from the upload script. As mentioned to need to use "response" not fileObj.name. fileObj.name is the name of the file as selected in the browse dialog, response is the echoed data. Your corrected function below.
    'onComplete': function(event, queueID, fileObj, response, data) {
    $('#filesUploaded').append('<a href='+fileObj.filePath+'>'+response+'</a><br>');
    }
  • hi there, this totally helped me! thanks!

    However, I have a question, when I do fileObj.filePath, and I am testing on my local machine, I dont get the http:///localhost/thedir/myfile all I get is: /thedir/myfile

    how can I make it so it displays the full url?
  • flash wont return the full url. But as you are running the script and uploader on your server you already know the address, so you can just concat the known address with the returned address.
  • response returns this for me:
    Array ( [folder] => /users/images [PHPSESSID] => 34g34gy5gf4fggvf5scv5g4yvs5g6yv ) 000001_e59m614017.jpg
    how do i filter this so i can put some thing like response.folder + response.name
    or just grab the file value after the array and if i can grab the folder value out of the array.