I want to make an image upload API Example:http://mysite.com/api.php?url=http://test.com/1.jpg How to write a script can get the image URL from the URL? Also check.the extension of the image Then upload to my site and redirect to the image. Thanks.
Asked
Active
Viewed 1,371 times
-3
-
1We won't help you until you try something and get stuck. – Daedalus Oct 08 '12 at 03:23
-
if I may, why are you trying to re-invent the wheel when you already have N jquery based api(s) doing the same for you? e.g. blueimp? – Satya Oct 08 '12 at 03:24
-
I tried many way to do it,eg.substr.but not working – user1727651 Oct 08 '12 at 03:28
-
I already have a jQuery signal upload script,but I don't know how to get the image URL from the post URL – user1727651 Oct 08 '12 at 03:32
1 Answers
0
Have api.php run a cURL command on your server to get the URL of the file submitted to your API then download the file where you want. Have it then return the location of the image to your script for final processing to include renaming and any database storage you want to accomplish.

rws907
- 787
- 4
- 14
- 25
-
-
If you can that would be news to me. You would need cURL to process the image fetch - or maybe use exec() and wget. I have never tried the latter but give it a shot. Why wouldn't you want to store the image information in the database? There seems to be a lot of information you could collect for analysis and reporting later. – rws907 Oct 08 '12 at 03:42
-
In PHP file can be read over the network into a string with file_get_contents function, no need for cURL or wget. http://php.net/manual/en/function.file-get-contents.php – divanov Oct 10 '12 at 10:03
-
True... I guess this StackOverflow article makes it as easy at it can be... http://stackoverflow.com/questions/724391/saving-image-from-php-url-using-php – rws907 Oct 10 '12 at 21:13