rick Posted November 13, 2019 Share Posted November 13, 2019 Howdy folks! This topic has already been beat to death here, here, here, here. I'm late to this party trying to find a stick in which to beat this horse. Good news is, I found a stick and have been flailing away. Bad news is, the horse is still dead. I am not able to save a selected image from a front-end form to a page image field using any of these methods. Here is an image representing the code (center) and dumps (Left and Right) at key positions. The temp path (Dump section 1) is created and appears in the file system. The WireUpload (Dump section 2 Left and expanded Right) show that the selected file was added to the wireupload. The $files variable assigned the execute results (Dump section 3, Left) shows an empty array was created. The $userProfile (Dump section 4) does not show details but does not include any new image saved to an images field. Another curiosity is: Notice the first line of code referencing the php global $_FILES. This is the only way to retrieve the selected image. $inputt->post('imagefield') returns null. I do not receive any error messages. The image itself is created from JQuery Filereader and is a base64 image and I can retrieve the raw data from a hidden field which shows a preview of the photo correctly. data:image/jpeg;base64,/9j/4... I've also tried the following: list($type, $img) = explode(';', $img); list(, $img) = explode(',', $img); list($type,) = explode('/',$type); $img = base64_decode($img); $img = $img . '.' . $type; I've passed the $img variable to the WireUpload function. No error is presented. The WireUpload shows the settings (filename, temp path, etc.) and an empty array as before. I'm runnin' 3.0.142, php 7.1, and apache 2.4.x So I have two questions: 1. Why is does WireUpload not return the file in an array? 2. Why does $input->post('imagefield') not return the selected file from the form. I hope that I have been detailed enough. If not, please let me know and I'll add the requested information. Thank you all for your help. Link to comment Share on other sites More sharing options...
horst Posted November 13, 2019 Share Posted November 13, 2019 17 minutes ago, rick said: 2. Why does $import->post('imagefield') not return the selected file from the form. What is $import->post() ?? Do you mean $input->post() ? Link to comment Share on other sites More sharing options...
rick Posted November 13, 2019 Author Share Posted November 13, 2019 3 minutes ago, horst said: What is $import->post() ?? Do you mean $input->post() ? Thanks for catching that! I've edited my original post. 1 Link to comment Share on other sites More sharing options...
psy Posted November 14, 2019 Share Posted November 14, 2019 @rick Rather than use the problematic PW front-end image uploads, I went for uppy and with @Robin S' amazing help, got it working. Tus/Uppy has a nice drag-n-drop user interface, overcomes file size limits, allows for resumable uploads + more. In Robin's example, he saves the images to a new page. In my case, I prepended the page id and an underscore to the filename in the Uppy js code. Then, in the uppy server page code, identify the required page by exploding the filename on the underscore. Maybe time to get a new horse? 2 Link to comment Share on other sites More sharing options...
horst Posted November 14, 2019 Share Posted November 14, 2019 1 hour ago, psy said: Maybe time to get a new horse? Haha! Good advice! :-) 1 Link to comment Share on other sites More sharing options...
rick Posted November 14, 2019 Author Share Posted November 14, 2019 Thanks @psy, I'll definitely try saddling a new horse. I'll miss the old horse. She was a beauty. 2 Link to comment Share on other sites More sharing options...
rick Posted November 14, 2019 Author Share Posted November 14, 2019 Sadly, the rider of this new horse is dumber than a truck-load of doorstops. So I found another way to accomplish what I was looking for. In my opinion, it's hacky, as I still don't know the answers to my op questions, but it will work for now. The $_FILES['input_file_fieldname']['tmp_name'] works as the parameter to New WireUpload(). The result is a randomly created name saved in both the PageImages and file system. Using Soma's rename procedure to provide the original uploaded file's name corrects that anomaly. The result is an uploaded image with the correct (human readable) name. Anyone want to buy a horse? Only ridden once. Includes a new stick. Cheap. 3 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