Tom. Posted November 8, 2018 Share Posted November 8, 2018 I have a script that I would like to upload and make sure the files keep it's file name. This is a multi-image image field. Just using $p->images->add($_FILES['file']['tmp_name']) works. However this doesn't: if(count($_FILES['file']) != 0) { $p->images->removeAll(); $u = new WireUpload('file'); $u->setDestinationPath($p->images->path); foreach($u->execute() as $filename) $p->images->add($filename); } if(!$error) $p->save(); There is no error given, however non of the images are added? What am I missing here? Edit: print_r($u); print_r($u->execute()); Both return an empty array. I'm guessing WireUpload('file') doesn't use $_FILES and there for can not be used with DropZone? Edit2: WireUpload does use $_FILES. There is some sort of bug happening here with using Ajax and WireUpload. Link to comment Share on other sites More sharing options...
bernhard Posted November 8, 2018 Share Posted November 8, 2018 1 hour ago, Tom. said: Edit: print_r($u); print_r($u->execute()); 1 hour ago, Tom. said: What am I missing here? You are obviously missing TracyDebugger ?? SCNR, but joke aside, tracy does also help you a lot on ajax debugging. It has fl() = firelog and bd() = bardump that can help a lot to see what's going on! A quick guess: If you are using custom AJAX scripts it might be the case that the headers are not set correctly so that PW recognizes it as $config->ajax == true. Maybe that's not at all helpful, not sure, but in a hurry ? 2 Link to comment Share on other sites More sharing options...
Tom. Posted November 8, 2018 Author Share Posted November 8, 2018 38 minutes ago, bernhard said: You are obviously missing TracyDebugger ?? SCNR, but joke aside, tracy does also help you a lot on ajax debugging. It has fl() = firelog and bd() = bardump that can help a lot to see what's going on! A quick guess: If you are using custom AJAX scripts it might be the case that the headers are not set correctly so that PW recognizes it as $config->ajax == true. Maybe that's not at all helpful, not sure, but in a hurry ? I believe it's an issue with DropZone. I've decided to do the following: if(count($_FILES['file']) == 0) { $error = "Please upload your entries."; } else { $count = count($_FILES['file']['name']); for($i = 0; $i < $count; $i++) { $file = $p->images->path . $sanitizer->pageName($_FILES['file']['name'][$i]); if(move_uploaded_file($_FILES['file']['tmp_name'][$i], $file)) { $p->images->add($file); } } } if(!$error) $p->save(); Which works a charm ? Thanks @bernhard 1 Link to comment Share on other sites More sharing options...
Tom. Posted November 8, 2018 Author Share Posted November 8, 2018 It would be really good if image->add had a second argument for image name ? Link to comment Share on other sites More sharing options...
markus_blue_tomato Posted January 12, 2023 Share Posted January 12, 2023 On 11/8/2018 at 3:27 PM, Tom. said: Edit2: WireUpload does use $_FILES. There is some sort of bug happening here with using Ajax and WireUpload. got some similar troubles where $_FILES has the file but WireUpload->execute() is an empty array. I do some POST request JavaScript Fetch API. 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