Okay here it is: (I am changing this post's content for the third time to explain better)
My website is an Image Hosting website, meaning the user can upload to my website and receive a direct link to his/her uploaded image.
I need some sort of API/way to communicate from my site with my users. I want users that are registered to my website be able to UPLOAD IMAGES from their website to my Image Host without them having to leave their own website (AJAX, iFrame, cURL, JSON, whatever it takes).
The request to my website should include a &request=api
paramater so the user gets plain text returned from my upload.php script. This way I think I ensure an easier way of grabbing data/output from my site.
So, basically, AFTER a POST/FILES request from the user's site to my Image Host, they receive link(s) from my upload processing script, which they need to retrieve and then use for their own needs.
My question is: My registered user sends a file to my server WITHOUT reloading the page and gets back the URL(s) to that image. How do I do this?
What I have tried:
All my tries were blockages with no continuing.
First, I added two new columns to two different tables. My users table received an api_key
column, which was intended to store an API key if the user actually signs up for it. The other column is_api
was added to the table where I store image information, only registered users have their images stored in the database. With this new column (which was type TINYINT
) I wanted to check that the image coming from the user was (or was not) added/uploaded via the API.
User sends a request to my Image Host with these parameters: upload.php?submit=true&action=upload&request=api&key=_SOME_API_KEY_
. I take the API key and check whom it belongs to -> Retrieve an user id based on that key -> I store the image to my server -> I store image information in my database (have an user id now) -> I echo
out the URL.
My failures here were:
- I couldn't send ANYTHING from the 3rd party website to my Image Host asynchronously
- I couldn't receive anything back to my 3rd party website.
Why these failures? Because I have no idea how to achieve these two most important steps.
One of my ideas to stop trying to send $_FILES[]
to my Image Host, was trying to send an IMAGE STRING via POST to my server and create the image there myself. I couldn't do this either, it was just a thought of a guy who had time to think.
So, this is it: My big problem with no solution from myself.
If you need more information in order to help me out more easily, please ask.
Thank you.
Update
If I just could receive the file somehow (asynchronously) I'd register it in the database with the is_api
field with a value of 1, to mark it as put via the API (external). This way, I could create a a new file named viewer.php
maybe and it would accept some parameters too like viewer.php?request=api&key=_API_KEY_
and it would return a JSON page with the link to the latest image by that external api user. Retrieving the page via JSON by the 3rd party website would be quite easy. So, with this method, I basically just need to receive the image somehow in my Image Host and the retrieving part wouldn't be too hard. So how would I send an IMAGE STRING to my Image Host via POST?
If this new idea of mine is exploitable, please let me know.