On my site lots of images are being used which are currently being stored on my server. But bandwidth is increacing quite alot and I want to store them on somewhere like Tinypic or Imageshack

So my request is an image uploader to a free host using cURL.

What I would need is something very simple. Mabey just a URL variable to feed the script the image URL.

Would someone be able to do this for me? Ive been trying for a while to no avail.

Something like this is brilliant but every time I try to rip it apart to get exactly what I need it stops working.

post your code that you changed. and we will help you.

what do you mean it stops working?

i don't think this is really that hard. its looping through a list of urls and using curl to post to another server. then parsing those results to get the info you need.

Here is the code. Its fairly simple but when I try to change it, it stops working.

<html>
<head>
<title>Batch ImageShack.Us Remote Uploader</title>

<link rel="stylesheet" href="style.css" type="text/css" media="screen" />

<script type="text/javascript">
function hl(codes){
codes.focus();
codes.select();
}

function copy(ini){
var urlSwf = "http://ndutsipit.co.cc/_clipboard.swf";
// Copy the text inside the text box to the user's clipboard
var flashcopier = 'flashcopier';var divholder = document.createElement('div');divholder.id = flashcopier;document.body.appendChild(divholder);divholder.innerHTML = '';var divinfo = '<embed src="' + urlSwf + '" FlashVars="clipboard='+escape(ini.value)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';divholder.innerHTML = divinfo;hl(ini);window.status = 'Copied text to clipboard';return false;
}
</script>

</head>
<body>
<div id="wrap"><div id="content">
<h2>Imageshack.Us Batch Remote Uploader</h2>
<form action="" method="post">
<textarea id="links" name="links"></textarea> <br />
<input type="submit" value="Remote Links" name="submit" id="submit"/>
</form>

<div id="result"><center>
<?php
if (isset($_REQUEST['submit'])) {
	
	//calculates time
	$time = explode(' ', microtime());
	$time = $time[1] + $time[0];
	$begintime = $time;
	
	$alllinks = @$_POST['links'];
	$alllinks = explode(" ", $alllinks);
	$alllinks = implode("\n", $alllinks);
	$alllinks = explode("\n", $alllinks);
	$x = 1;
	
	$alllinks = array_unique($alllinks); //check duplicates
	
	foreach($alllinks as $link) {
	
	$link = trim($link); //removes duplicates
		
		if (preg_match("/\bhttp\b/i" , "$link")) { //find only link 
		
		$img = urlencode($link);
    
	    //set POST variables  
	    $CURL_URL = 'http://www.imageshack.us/transload.php';  
	    $fields = array('url'=>$img,'MAX_FILE_SIZE'=>"13145728",'uploadtype'=>"on");  
	     
	    //url-ify the data for the POST  
	    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }  
	    rtrim($fields_string,'&');  
	     
	    //open connection  
	    $ch = curl_init();  
	     
	    //set the url, number of POST vars, POST data  
	    curl_setopt($ch,CURLOPT_URL,$CURL_URL);  
	    curl_setopt($ch,CURLOPT_POST,count($fields));  
	    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);  
	    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);    
	    $result = curl_exec($ch);  
	    curl_close($ch); 
    
		    if (empty($result))
		    {
		        print "Something went wrong with Imageshack?";
		    }
		    else
		    {
		        // Find the Hosted Image Link
		        if(preg_match_all("#\<input type\=\"text\" onclick\=\"highlight\(this\)\" style\=\"width\: 500px\" size\=\"70\" value\=\"\[URL\=http\:\/\/imageshack\.us\]\[IMG\](.*)\[\/IMG\]\[\/URL\]\"\/\>#", $result, $matches)) {   
		        
				echo '<b>'.$x.'</b> <input type="text" class="inputcode" value="'.$img = $matches[1][0].'" onfocus="javascript:copy(this)" readonly ><br />';
				echo '<small><i>original : '.$link.' </i></small><br />';
				$x++;
				
				} else {
				
				echo '<b>'.$x.'</b> <input type="text" class="inputcode" value="Warning! Image type not valid or supported." onfocus="javascript:copy(this)" readonly ><br />';
				echo '<small><i>source : '.$link.' </i></small><br />';
				$x++;
				
				}
				
		    }		
		
		} 
		
	}
	
	$time = explode(" ", microtime());
	$time = $time[1] + $time[0];
	$endtime = $time;
	$totaltime = ($endtime - $begintime);
	$x--;
	$plural = ($x == 0) ? "" : "s";
	echo "<div class=\"inputcode\"><p><b>- $x image$plural remoted in <font color=\"#800000\">$totaltime</font> seconds -</b><br /><br /></p></div>";

}

	echo "<small><b>$total images was uploaded!</b></small>";
	
?>
<br /><br />
<p>
- <a href="http://blog.smileylover.com/" title="Learn and Share"><em>You can download this script free in here</em></a> -
</p>
</center></div><!--result-->
<div id="footer">
<small>
<a href="http://smileylover.com/" title="Friendster Smiley, MySpace Smiley, Forum Smiley">SmileyLover</a> |
<a href="http://mp3.smileylover.com/" title="Friendster MP3, Free MP3 Player Codes">Friendster MP3</a> |
<a href="http://rapidcheck.co.nr/" title="Universal AJAX Link Checker">AJAX Link Checker</a> |
<a href="http://imageremoter.co.nr/" title="Imageshack.Us Batch Remote Uploader">Image Remoter</a>

</small><br /><br />
- SmileyLover &copy; 2008 -
<br /><br />
  <!-- Histats.com  START  --> 
 <a href="http://www.histats.com" target="_blank" title="php hit counter" > 
 <script  type="text/javascript" language="javascript"> 
  
 var s_sid = 423474;var st_dominio = 4; 
 var cimg = 306;var cwi =118;var che =60; 
 </script> 
 <script  type="text/javascript" language="javascript" src="http://s10.histats.com/js9.js"></script> 
 </a> 
 <noscript><a href="http://www.histats.com" target="_blank"> 
 <img  src="http://s4.histats.com/stats/0.gif?423474&1" alt="php hit counter" border="0"></a> 
 </noscript> 
  
 <!-- Histats.com  END  --> 

</div><!--/footer-->
</div><!--/content--></div><!--/wrap-->
</body>
</html>

what did you change? i don't have time to compare them.

Ah dont worry. It was my own stupidity :p I just got lazy and the code was very messy.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.