0

I want to make a PHP script that let user browse image from their computer, then upload it to an image hosting server, and by image hosting server, I mean image hosting services like imageshack.us, photobucket, or blogger.com... I think there are four steps for this:

  • Display upload form which let user browse image
  • Upload image to my server
  • Copy them to image hosting server (use my image hosting account)
  • Get uploaded image link (from hosting server, not mine)

How ever, I only know what to do with the first and second step, I don't have any idea for the rest. Please give me some suggestion, what should I do to get step 3 and step 4 done, what function should I use, is it possible to have php just open the page and click the button I want to upload image, something like that. Thank you for any help!

Mee
  • 815
  • 5
  • 11
  • 21

2 Answers2

1

For imageshack.us

check http://api.imageshack.us/ and for request the access http://imageshack.us/api_request/

and to send files check this answer https://stackoverflow.com/a/14571212/829533

<?php
    $url = 'http://imageshack.us/upload_api.php';
    $key = KEY;
    $max_file_size = '5242880';
    $temp = $_FILES["fileupload"]["tmp_name"];

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_URL, $url);

    $post = array(
        "fileupload" => '@' . $temp,
        "key" => $key,
        "format" => 'json',
        "max_file_size" => $max_file_size,
        "Content-type" => "multipart/form-data"
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    $response = curl_exec($ch);
    $json_a=json_decode($response,true);
    echo $json_a[links][image_link];
?>

the form will be like

<form method="post" enctype="multipart/form-data" action="upload.php">
    <input type="file" name="fileupload"/>
    <input type="submit" value="Go"/>
</form>
Community
  • 1
  • 1
zzlalani
  • 22,960
  • 16
  • 44
  • 73
-1

According to your question, I found that you have a server, I think that ImageS3 may be an option for your to upload images to.

If you use ImageS3 as your image hosting service, then the steps would be looks like:

  • Display upload form for users to browse image.
  • Directly upload image with ImageS3 rest api.

    POST image to http://you-server-url/rest/v1/imageplants/<imageplant id>/images/

  • Get uploaded image (origin or thumbnails) from the ImageS3 rest api.

    GET http://you-server-url/rest/v1/imageplants/<imageplant id>/images/imageId?template=

You can check out this project at https://github.com/images3/images3-play, and REST API reference at http://docs.images3api.apiary.io/.

Cheers,

stevesun21
  • 1
  • 1
  • 2