Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload