Howdy, Stranger!

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

I get "1" instead of the filename
  • Everything works great, size limit, extension restriction, but I´m trying to get the filename and I get "1" instead.

    This is the code I's using:

    <li>
    <label>Imagen<span class=\"small\">Imagen en formato JPG o PNG menor de 200kb.</span></label>
    <input id=\"fileUpload\" name=\"fileUpload\" type=\"file\" />
    <script type=\"text/javascript\">// <![CDATA[
    $('#fileUpload').uploadify({
    'uploader': '../js/uploadify/uploadify.swf',
    'script': '../js/uploadify/uploadify.php',
    'folder': '../images/uploads',
    'checkScript': '../js/uploadify/checkscript.php',
    'cancelImg': 'cancel.png',
    'fileDesc': 'Imágenes .jpg, .png',
    'fileExt': '*.jpg;*.png',
    'auto':true,
    'sizeLimit': 200000,
    'onComplete': function(event, queueID, fileObj, response, data) {
    $('div#archivos').append(\"- <b>\" + response + \"</b> <span style='color: green;'>ok!</span><br />\");
    //$('div#archivos').append(fileObj.name + \" ok!<br />\");
    $('#uploadhidden').val($('#uploadhidden').val() +response+ ',');}
    });
    // ]]></script>

    <!-- <a href=\"javascript:$('#fileUpload').uploadifyUpload();\">Upload Files</a> -->

    </li>
    <input name=\"uploadhidden\" type=\"hidden\" id=\"uploadhidden\" />
    <div id=\"archivos\"></div>


    I got this from another website and it works in that one.

    Could somebody help me please!!!
  • on the uploaddify.php you will find a line near the end that says echo "1";
    You can delete it and echo whatever you want and get it on the onComplete response callback.

    So if you want to get the filename you should have this instead of echo "1"; in uploadify.php:
    [code=php]
    echo $_FILES
    ['Filedata']['name'];
     [/code]
  • fileObj.name is the filename of the file at the time it was selected. If your looking for the filename as you have saved it in the upload script then you must do it as ptejada has said above. Response is simply what ever is echoed in the upload script.
  • Thanks a lot to both of you for the quick response. It worked!!

    I´m still playing with the script.

    I'm trying to build an app that when you upload:

    1. Check if the file exists
    2. If it exists just rename it and store the file name in the hidden input
    3. Finish by submitting everything in the form to a DB

    I've read a lot of the stuff others wrote about this, but still can't find one that I actually understand to rename the file.

    Could you guys point me to the right direction please?

    Thanks
  • lachojr said:
    Thanks a lot to both of you for the quick response. It worked!!

    I´m still playing with the script.

    I'm trying to build an app that when you upload:

    1. Check if the file exists
    2. If it exist just rename it an store the file name in the hidden input
    3. Finish by submitting everything in the form to a DB

    I've read a lot of the stuff others wrote about this, but still can't find one that I actually understand to rename the file.

    Could you guys point me to the right direction please?

    Thanks

    i have this done on the website that i working on... i'll posted it later im in hurry now...
  • Ok... thanks ptejada!! I'll be waiting for your post
  • This is a costume uploadify.php file that will rename any existing file and echo the file name:
    [code=php]
    if 
    (!empty($_FILES)) {
        
        $tempFile 
    = $_FILES['Filedata']['tmp_name'];
        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
        $filename = $_FILES['Filedata']['name'];
        $targetFile =  str_replace('//','/',$targetPath) . $filename;
        
        
    //Avoid files Overwrite
            while(file_exists($targetFile)){
                $user = "g".rand(0,100);
                $filename = $user."-". $_FILES['Filedata']['name'];
                $targetFile =  str_replace('//','/',$targetPath) . $filename;
            }      
        move_uploaded_file
    ($tempFile,$targetFile);
        echo $_FILES['Filedata']['name'];
     [/code]
  • Thanks ptejada. Got it working!!!

    Actually, in order to get the new file name the last sentence is

    echo $filename;


    instead of

    echo $_FILES['Filedata']['name'];


    Now I only have to just rename it instead of displaying the confirm alert. I think I saw a post about that one.

    Thanks for all your help!!
  • Sure no problem i missed that one, glad you got it working...
    while using this method you wont need the Check.php file so you can remove it from your jquery uploadify call.

    So judging from your first post you just have to delete this line from the uploadify jQuery call and you wont see that confirmation message:

    'checkScript': '../js/uploadify/checkscript.php',
  • Got it already without the alert. Thanks ptejada!!

    For my app to be complete I only need that the file uploads at the time you the submit form with all the other data.

    I want to upload it at the time you hit the submit button so you can save server space.

    How would you do that?

    Has anyone already done it??
  • First set auto to false in the uploadify call and then you can use this function to star uploading:

    $('#id').uploadifyUpload();

    Where #id is the ID of the input where you called the uploadify function to...
  • i managed to rename the file when uploading.. but how can i passed the new name to my javascript+ajax to be sent to mysql..??
  • Use the onComplete event -- fileObj is passed into that and you can grab the name with fileObj.name and then call a function that does your ajax/mysql process.

    Something like this in uploadify:

     'onComplete': function(event, queueID, fileObj) { SaveToDB(fileObj.name); },


    And then...

    function SaveToDB(uploadName)
    {
    // do ajax thing here
    }


    Jay Jennings
  • He can't just get the filename using the object fileObj.name because the filename has been renamed, he can get the new filename from the response of the onComplete event.
  • Oops, sorry about that -- I pass in the new name to my upload script so I don't *have* to keep track of it. I just grab the name when it comes back and modify it again before I save it.

    But I just went and looked at the docs and it doesn't say anything about what's in response when it comes back. Anybody know where that's documented? Or is that just whatever's echo'd from the server script?

    Jay Jennings
  • Jay Jennings said:
    Oops, sorry about that -- I pass in the new name to my upload script so I don't *have* to keep track of it. I just grab the name when it comes back and modify it again before I save it.

    But I just went and looked at the docs and it doesn't say anything about what's in response when it comes back. Anybody know where that's documented? Or is that just whatever's echo'd from the server script?

    Jay Jennings

    Correct, the response is whatever that PHP script outputs, you can always get fancy like i did and return a JSON object with detailed information of the new resize image and thumbnails. If you don't what JSON is you could always google it...
  • is it possible to do the same (get the new filename) with aspx and c#??