Jump to content

[Horse for sale] Front-end image upload fails


rick
 Share

Recommended Posts

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.

code01.thumb.jpg.be88f3ee2650c0550a934202cde11d0e.jpg

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

@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?

 

  • Like 2
Link to comment
Share on other sites

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.

  • Haha 3
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...