File upload API, port an Jquery uploader

Discussion forum for MOD Writers regarding MOD Development.
Locked
olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

File upload API, port an Jquery uploader

Post by olsserik » Tue Aug 25, 2015 10:00 am

Hi,
Im about to port an Jquery upload script to my forum 3.0.13.
The uploader works great when testing, it has a php backend where multiple images can be uploaded, cropped, rotated and so on and it callbacks via Jquery ajax so the user can see what happens when e.g rotate an uploaded image (a thumbnail).

This script uses an own folder (I use a "files2" set to 777) where the script stores thumbnails and original images.

When a user are finished with modifying an image, Jquery sends back an event that today is the full path to the image.

Is there a simple way, maybe via API/function to use this path and send it through the standard attachment upload procedure?
Im thinking of adding a button below the thumbnail (that now are present in posting.php under upload attachment) so when the user are satisfied with the images, a button can bli clicked - "post images" or so and when clicked, the images that are sent via Jquery event can be uploaded in "standard way".

Any ideas on this?

User avatar
AmigoJack
Registered User
Posts: 5599
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: File upload API, port an Jquery uploader

Post by AmigoJack » Wed Aug 26, 2015 6:24 am

jQuery on its own is unable to manipulate files - it must be the PHP end that is doing that. And then the manipulated picture is already on the server. You have to copy and adapt the existing routines to enter the point when the (already) uploaded files are moved. Your example is also forgetting that attachments aren't always pictures, and you need to start in the posting editor (to make a post or compose a PM) - which means you want to change something existing, instead of starting a new way which ends in an existing one.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: File upload API, port an Jquery uploader

Post by olsserik » Wed Aug 26, 2015 11:48 am

Hi,
Yes, but as I stated in previous post there is a PHP backend doing the cropping, thumbnail and rotating.
Jquery spits back an url to the manipulated image and the question was:

In posting.php, could existing file upload methods be used to upload this image?

Im thinking of local_upload function but havent figured out how it works.
Or maybe go deeper into the process and hook on this url to the existing process och uploading.

My intention is to leave phpbbs upload function untouched and run this uploader in parallell with existing attachment system.

I managed to get the non-phpbb uploader to pass the url containing bbode [img] and that works. The bad thing is that these images does not have no belonging to a certain post/topic and that I would really like.

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51760
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: File upload API, port an Jquery uploader

Post by Brf » Wed Aug 26, 2015 11:55 am

olsserik wrote: In posting.php, could existing file upload methods be used to upload this image?
No. That would be a security problem if a server on the Internet could access and upload files from a user's computer. The uploading itself has to be done by the HTML or Javascript. After the upload is done, the PHP grabs the file and does whatever to it.

olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: File upload API, port an Jquery uploader

Post by olsserik » Wed Aug 26, 2015 12:01 pm

Ok, thank you!

But could local_upload be used for this?

https://area51.phpbb.com/docs/code/3.0. ... cal_upload

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51760
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: File upload API, port an Jquery uploader

Post by Brf » Wed Aug 26, 2015 12:03 pm

Used for what?

olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: File upload API, port an Jquery uploader

Post by olsserik » Wed Aug 26, 2015 12:11 pm

Used for grabbing an image file from a folder within phpbb.

The uploader script uploads images to dedicated folder, lets call it tempimg.

Can local_upload be used then to upload e.g

http://myphpbbsite.com/tempimg/testimg.jpg

if I use local_upload from within http://myphpbbsite.com

Do you know what I mean?
Sorry if I suck at explaining this but Im trying.

Another explaining:

Could local_upload (or some other method) be used to add attachments to a post from an local folder on the same server?

User avatar
Brf
Support Team Member
Support Team Member
Posts: 51760
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}
Contact:

Re: File upload API, port an Jquery uploader

Post by Brf » Wed Aug 26, 2015 12:16 pm

I would assume so. That is the way the attachments system works.

olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: File upload API, port an Jquery uploader

Post by olsserik » Wed Aug 26, 2015 12:36 pm

Ok!
Is there any wiki page or similar describing the phpbb upload process (3.0)?

I have looked for this but no luck.


olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: File upload API, port an Jquery uploader

Post by olsserik » Thu Aug 27, 2015 8:15 pm

Hi Viola and thanks.
I´ve looked over Plupload but it lacks in mobile web browsers, uses Flash and have possible security issues (XSS) so I will not go for that, sorry.

olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: File upload API, port an Jquery uploader

Post by olsserik » Fri Sep 04, 2015 12:59 pm

Hi,
Im struggling with getting already uploaded images to a phpbb server passed through the phpbb upload process (so images can be assigned to posts).

I tried to use

Code: Select all

local_upload
function in includes/functions_upload.php (around line 670) and made some modifications to includes/message_parser.php function (line ~1370):

Original:

Code: Select all

$upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : false;
To:

Code: Select all

$upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : (!empty($_POST['filupload'])) ? true : false;
And then to includes/functions_posting.php (line ~420)

Original:

Code: Select all

$file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name);
To:

Code: Select all

$file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : (!empty($_POST['filupload'])) ? $upload->local_upload($_POST['filupload']) : $upload->form_upload($form_name);
After that Im trying to add input type hidden with value: "full-path-to-image-on-server.jpg" and name="filupload" (removed an "e" so its not the same as form_upload) to the existing attachment function in posting.php (posting_attach_body.html).

This seems to function except when it stops on functions_upload.php (line ~670):

Code: Select all

			if (function_exists('mime_content_type'))
			{
				$mimetype = mime_content_type($source_file);
			}
It fails with warning: mime_content_type(): Failed identify data 0:(null)

In some way it can not read the mime_type from that image and I dont know why (it fetches the correct image, I´ve tried that).
Anyone that has any idea, or even better, a better way to pass already uploaded images through the phpbb file upload process?

User avatar
ViolaF
Registered User
Posts: 1452
Joined: Tue Aug 14, 2012 11:52 pm

Re: File upload API, port an Jquery uploader

Post by ViolaF » Sun Sep 06, 2015 6:47 pm

olsserik wrote:Hi Viola and thanks.
I´ve looked over Plupload but it lacks in mobile web browsers, uses Flash and have possible security issues (XSS) so I will not go for that, sorry.
Sorry but plupload is used in current phpBB Version 3.1.* :lol:

olsserik
Registered User
Posts: 155
Joined: Tue Aug 21, 2007 6:18 am

Re: File upload API, port an Jquery uploader

Post by olsserik » Fri Sep 18, 2015 10:33 am

Viola: Nevertheless, search for plupload and security and start reading. Involving flash and Silverlight and other things is creepy. Also users seems not to be able to rotate uploaded images with plupload, that´s one of my users main request.

This topic can be closed, I managed to port the Jquery uploader. It did not work via local_upload, had to go through S_FILES.

Locked

Return to “[3.0.x] MOD Writers Discussion”