Frank Vèssia Posted February 6, 2014 Share Posted February 6, 2014 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 More sharing options...
adrian Posted February 6, 2014 Share Posted February 6, 2014 From what I understand, you want to be able to rename an image during the upload process. A couple of options: Install Custom Upload Names and define rules for what files should be named what Hook into Pagefile::install and work with this code from Ryan Let us know if you need any specific help. 2 Link to comment Share on other sites More sharing options...
horst Posted February 6, 2014 Share Posted February 6, 2014 (edited) https://www.google.de/search?q=site:modules.processwire.com+custom+filename+upload EDIT: Oh, shit, it tooks me to long to google it! Adrian was faster! Edited February 6, 2014 by horst 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 6, 2014 Author Share Posted February 6, 2014 Thanks guys, didn't know about this module... Link to comment Share on other sites More sharing options...
adrian Posted February 6, 2014 Share Posted February 6, 2014 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 More sharing options...
Frank Vèssia Posted February 6, 2014 Author Share Posted February 6, 2014 I'm going to implement it via API, I'll let you know asap, thanks for now. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 12, 2014 Author Share Posted February 12, 2014 @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 More sharing options...
adrian Posted February 12, 2014 Share Posted February 12, 2014 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. 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 12, 2014 Author Share Posted February 12, 2014 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 More sharing options...
adrian Posted February 12, 2014 Share Posted February 12, 2014 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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now