Jump to content

hook for wireupload filename images


Frank Vèssia
 Share

Recommended Posts

since upload on iOs returns filename "image.jpg", there is a way to hook the WireUpload "execute" function and pass custom filename for each uploaded images?
 
 

<?php
$u = new WireUpload('qqfile');
$u->setMaxFiles(5);
$u->setOverwrite(false);
$u->setDestinationPath($config->paths->root . "tmp_uploads/");
$u->setValidExtensions(array('jpg', 'jpeg'));
$files = $u->execute();
Link to comment
Share on other sites

Please let me know how you go with that module. There are some very recent changes in there that added support for API uploading on the front-end. Prior to that, it was only for admin uploads, so I'd like to hear about your experience with it and any changes you would like to see.

Link to comment
Share on other sites

@adrian I ended up replacing the uploaded file with custom code, maybe i'm wrong but your plugin is executed after the file is uploaded because it uses the pw field and i needed to rename the file before was saved to the field. so this is my code

<?php
    $u = new WireUpload('qqfile');
    $u->setMaxFiles(5);
    $u->setOverwrite(false);
    $u->setDestinationPath($config->paths->root . "tmp_uploads/");
    $u->setValidExtensions(array('jpg', 'jpeg'));
    $files = $u->execute();
    foreach($files as $file){
        $tempImg = $config->paths->root . "tmp_uploads/".$file;
        $newFile = $config->paths->root . "tmp_uploads/".$_POST['qquuid'].'.jpg';
        @rename($tempImg, $newFile);
        $resizedImage = new ImageSizer($newFile); 
        ...//other code
    }
?>
Link to comment
Share on other sites

Well I see that you are wanting to rename it based on the POST value for qquuid. My module is not designed to rename based on user supplied values at upload time, but rather standard formats set up in the config based on the values of PW fields. You could use my module to rename the file to the value of a qquid field. The only catch is that the field would have to be saved before the file was uploaded.

You have got me thinking that maybe my module would benefit from the ability to rename a file at any time if the value of a field used in the rename rule is changed.

  • Like 1
Link to comment
Share on other sites

The problem came when I upload an image using some iOs device. They overriding the original name, uploading everything with the name "image.jpg" so I have to rename the file immediately, right after the file is uploaded, otherwise there are good chances to overwriting files from different users, in my case...

Link to comment
Share on other sites

If you are worried about possible overwriting with users uploading at exactly the same time, perhaps you should consider uploading each user's files to a unique subfolder within the tmp_uploads folder. If the users are logged in users, rather than guests, you could name the subfolders based on the user's ID. If not, generate a unique name - lots of ways to do this in PHP. Anyway, just some ideas for you.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...