This forum is a community forum meant for users of the plugin to collaborate and help solve issues with implementation, etc. Unfortunately, as the creator of the plugin, I do not have much time to attend to every request here as this is only a side project and I must work a full-time job to provide for my family. This is how I keep the Flash version free and the HTML5 version low cost.
UploadiFive 1.1.1 has been released which includes a small fix for added support on touch devices including iOS 6 devices.
Uploading file with space in file name
  • Hello,

    I would like to know if it's possible to implement a feature to replace in the file name space by "_" when uploading

    mamax
  • you need to edit your upload.php. use the str_replace function to replace spaces with underscores.
  • I tried using the str_replace function in various places in the uploadify.php script, but not luck, it either continued uploading but did not change the spaces. Or it did not upload at all, although it looked like it did...

    How/where would this be implemented?

    Thanks
  • generally like this

    <?php
    $str = ' This is a test ';
    $count = 1;
    while($count)
    $str = str_replace(' ','', $str, $count);
    echo $str;
    ?>


    But maybe preg_replace is the better choice to clean everything bad from the filename

    $fname="Filen'ame 1\/23;".'"'."la\l[a]*(/.jpg";
    $replace="_";
    $pattern="/[^a-zA-Z0-9\.]/";
    $fname=preg_replace($pattern,$replace,$fname);
    $fname=str_replace($replace,'',$fname);
    echo '<br>'.$fname;


  • $var =$_FILES['Filedata']['name'];
    $name= ereg_replace(" ","_",$var);
    $targetFile = str_replace('//','/',$targetPath) . $name;
  • edit uploadify.php

    $var =$_FILES['Filedata']['name'];
    $name= ereg_replace(" ","_",$var);
    $targetFile = str_replace('//','/',$targetPath) . $name;
  • the space problem is easily solved as shown above.
    My problem is when there is stress on the file name is giving error.
    when the file name has these characters: "éçãáàõáò" becomes: "a aa © a § ¡¡to the aμa ²"
    anyone have any solution?
  • like I posted above , with preg_replace
  • That was all gold, thanks
  • This is my final php, which cleans the filename from spaces and other problematic chars,
    randomizes the filename afterwards and send it back to the backend:

    <?php
    if (!empty($_FILES)) {
    $replace="_";
    $newfile= $_FILES['Filedata']['name'] ;
    $ext = substr($newfile,-4); //comment out to not ramdomize the filename
    $pre = mb_split($ext,$newfile); //comment out to not ramdomize the filename
    $randoms = base_convert(mt_rand(0x1679616, 0x39AA3FF), 10, 36); //comment out to not ramdomize the filename
    $newfile = $pre[0].$randoms.$ext; //comment out to not ramdomize the filename
    $pattern="/[^a-zA-Z0-9\.]/";
    $newfile = preg_replace($pattern,$replace,$newfile);
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
    $targetFile = str_replace('//','/',$targetPath) . $newfile;
    move_uploaded_file($tempFile,$targetFile);
    chmod($targetFile,0777);
    echo $newfile; // Required to trigger onComplete function on Mac OSX (same for linux and windows as it seems)
    //and to send back the new filename to the 'response' variable in uploadify
    }
    else { // Required to trigger onComplete function on Mac OSX
    echo 'ERROR!';
    }
    ?>
  • This is great, but I have noticed that now the Checking script doesn't work quite right. check.php is looking to see if there are files with a different name, but the file we are uploading is going to have its name changed, how do account for that in the check script, another str_replace?

    How do we write that?
  • Actually I don't use the check script. In my case I have to upload hundreds of images and therefore I need to give the user the possibility to upload files, without worrying about the file name as he could want to upload a file named logo.gif for different datasets maybe ten times.
    That's why I added a random part to the filename. The $randoms very likely never gives the same result twice.
    I think you can't alter the check.php to follow the same rules, as the $randoms will be different even for the same finename, though

    I would be possible if you comment out the ramdomising part and only use the 'cleaning' part.
    Then the output is predictible.
    I haven't tested that, but it should be something like this:

    $fileArray = array();
    $replace="_";
    $pattern="/[^a-zA-Z0-9\.]/";
    foreach ($_POST as $key => $value) {
    if ($key != 'folder') {
    $value= preg_replace($pattern,$replace,$value);
    if (file_exists($_SERVER['DOCUMENT_ROOT'] . $_POST['folder'] . '/' . $value)) {
    $fileArray[$key] = $value;
    }
    }
    }
    echo json_encode($fileArray);

    This is just a quick guess, try if it works.
    And comment out the lines in upload.php which are indicated.
  • The user and all related content has been deleted.