Jump to content
rick

[Horse for sale] Front-end image upload fails

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.

 

Share this post


Link to post
Share on other sites
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() ?

Share this post


Link to post
Share on other sites
3 minutes ago, horst said:

What is $import->post() ?? Do you mean $input->post() ?

Thanks for catching that! I've edited my original post.

  • Like 1

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
1 hour ago, psy said:

Maybe time to get a new horse?

Haha! Good advice! :-)

  • Haha 1

Share this post


Link to post
Share on other sites

Thanks @psy, I'll definitely try saddling a new horse. I'll miss the old horse. She was a beauty.

  • Haha 2

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...