Howdy, Stranger!

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

Restrict Certain Filetypes and Display Error
  • I was wondering how to display an error message when the file type is restricted like .exe, .php, etc.

    So far, I got to here. (I'm doing this server side...through the uploadify.php script.)

    $filename = $_FILES['Filedata']['name'];

    $blacklist = array(\".php\",\".exe\");
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
    if(in_array($ext,$blacklist)) {
    die(\"Restricted File!\");

    }


    As you can probably tell, when I upload a .exe or .php file, it doesn't upload and dies. BUT uploadify doesn't actually output the die message either. Yes, the script dies and file wasn't uploaded, but it does NOT display anything. It still says file is completed on the progress bar box even though it's not. How can I make it so that if a file is blacklisted, two things will happen:

    1.) Instead of the filename box that shows the progress for completion; instead of saying "Completed" it will say, "Error" or something like that, and instead of the whole progress bar box being gone, it just stays there so the user can see it saying "Error" or something.

    2.) It will display an error message on the page, telling the user that the file was not uploaded.
  • you could use onSelect and black list file types there. Display and alert and remove the file from the upload queue. you could implement something similar to what I posted here http://uploadify.com/forum/viewtopic.php?f=7&t=4857#p8915
  • I have a really, really minimal knowledge at JS, and I don't know what to do. I am more of a PHP type of person, so that's why I was using PHP.

    If we really have to use JS, can you provide me the exact coding for the JS, and/or upload.php? Thank you. Otherwise, can you guide me on what to do also if we were to do it in PHP? I just need the uploadify script to echo a message...I mean, I got the PHP done..
  • Anyone?
  • Just for you people that don't have the patience to work it out for them selves :!: ; the following will only allow .tiff images to be added to the queue. If not .tiff alert() - (or do whatever you like). Example file types used below.

    $(document).ready(function() {
    $(\"#uploadify\").uploadify({
    'uploader' : 'scripts/upload/uploadify.swf',
    'script' : 'scripts/upload/uploadify.php',
    'checkScript' : 'scripts/upload/check.php',
    'cancelImg' : 'images/cancel.png',
    'folder' : 'upload',
    'queueID' : 'fileQueue',
    'buttonText' : 'Browse',
    'auto' : false,
    'multi' : true,
    'onSelect' : function (event, queueID, fileObj) {
    var ext = fileObj.name;
    ext = ext.substr(ext.length-3); //gets last 3 chars (extention type)
    switch (ext) {
    case 'mp3':
    alert(\"Not a valid .TIFF file\");
    $jQuery('#uploadify').uploadifyCancel(queueID);
    break;
    case 'wmv':
    alert(\"Not a valid .TIFF file\");
    $jQuery('#uploadify').uploadifyCancel(queueID);
    break;
    case 'pdf':
    alert(\"Not a valid .TIFF file\");
    $jQuery('#uploadify').uploadifyCancel(queueID);
    break;
    case 'tiff':
    alert('All good continue');
    break;
    default:
    break;
    }
    }
    });
    });
  • This is a little modified Code, its a better idea to grab the last 4 chars (not only 3) because there are filetypes out with 4 chars.

    furthermore i included a whitelist, in the following example only file types JPEG,JPG,GIF are allowed, all other tile types will throw an error.

    function(event,queueID,fileObj){
    var ext = fileObj.name;
    ext = ext.substr(ext.length-4); //gets last 4 chars (extension type)
    switch (ext) {
    case \"jpeg\":
    case \".jpg\":
    case \".gif\":
    // filetype ok
    break;
    default:
    alert(\"filetype not ok\");
    $jQuery(\"#uploadify\").uploadifyCancel(queueID);
    break;
    }
    }
  • hey this script is great, but for for some reason when that JS alert comes up it freezes my browser....
  • I've tried the above script and the alert works fine but the cancel doesn't work, the file still gets processed.

    I've tried both uploadifyCancel(queueID) and uploadifyClearQueue() even though I'm only allowing one file at a time to be uploaded ('multi': false)

    Any ideas?