2012-02-28 53 views
1

本教程http://www.blocsoft.com/blog/imageshack.asp展示了一種上傳到ima​​geshack並獲取圖像url的好方法,雖然它的ASP和我需要它在PHP中。Imageshack API幾乎在工作

任何想法,如果和如何做到這一點?

感謝堆。

+2

難道沒有谷歌搜索的'ImageShack的API PHP'爲你工作時所顯示的工具?其中一些看起來很有希望。 – 2012-02-28 10:50:30

+0

他們看起來很有前途,但沒有做到我需要的東西(不像asp的) – 2012-02-28 10:58:29

回答

1

我只是重寫了ASP到PHP,沒有線索,如果它的工作沒有測試過,但如果ASP確實工作,那麼PHP也應該。

的index.php

<html> 
    <head> 
    <title>AJAX image upload</title> 
    </head> 
    <body> 
    <form action="http://imageshack.us/redirect_api.php" target="AXframe" method="post" enctype="multipart/form-data"> 
     <input type="file" name="media"/> 
     <input type="hidden" name="key" value="YOUR_DEVELOPER_KEY"> 
     <input type="hidden" name="error_url" value="http://example.com/error.php"> 
     <input type="hidden" name="success_url" value="http://example.com/success.php?one=%y&two=%u&three=%s&four=%b&five=%i"> 
     <input type="submit"/> 
    </form> 
    <iframe style="visibility:hidden" id="AXframe" name="AXframe"></iframe> 
    <div id="link"></div> 
    <div id="yfrog"></div> 
    <div id="image"></div> 
    </body> 
</html> 

success.php

<?php 
    $str1 = $_GET["one"]; 
    $str2 = $_GET["two"]; 
    $str3 = $_GET["three"]; 
    $str4 = $_GET["four"]; 
    $str5 = $_GET["five"]; 
?> 

<script type="text/javascript"> 
    parent.document.getElementById('yfrog').innerHTML = '<?php echo($str1); ?>'; 
    parent.document.getElementById('link').innerHTML = '<?php echo($str2); ?>'; 
    parent.document.getElementById('image').innerHTML = '<img src="http://img<?php echo($str3); ?>.imageshack.us/img<?php echo($str3); ?>/<?php echo($str4); ?>/<?php echo($str5); ?>">'; 
</script> 

error.php

<script type="text/javascript"> 
    alert("There was an error uploading the file."); 
</script> 
+0

謝謝,我現在會測試它 – 2012-02-28 11:02:54

+0

對不起,但它似乎沒有工作。我得到一個破碎的圖像圖標,沒有鏈接,圖像圖標指向imageshack上的一個空白點(http://img.imageshack.us/img//) – 2012-02-28 11:10:26

+0

我通過迴應成功的變量.php感謝堆! – 2012-02-28 11:17:25