1

This tutorial http://www.blocsoft.com/blog/imageshack.asp shows a great way to upload to imageshack and get a image url back although its for ASP and I need it in PHP.

Any ideas if and how this could be done?

Thanks heaps.

McDan Garrett
  • 183
  • 1
  • 3
  • 15

1 Answers1

1

I just rewrote the asp to php, no clue if it works haven't tested it, but if the asp does work then the php should also.

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>
SynerCoder
  • 12,493
  • 4
  • 47
  • 78
  • Sorry but it doesn't seem to work. I get a broken image icon and no links, and the image icon points to an empty spot at imageshack (http://img.imageshack.us/img//) – McDan Garrett Feb 28 '12 at 11:10
  • I got it working just by echoing the variables that are in success.php Thanks heaps! – McDan Garrett Feb 28 '12 at 11:17