I found a solution. I donĀ“t know if this is the better solution, but works fine.
index.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<form action="imagem.php" method="post" enctype='multipart/form-data'>
<input type="file" id="foto" name="foto" />
<input type="submit" value="Enviar" />
</form>
</body>
</html>
imagem.php
<?php
preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $_FILES['foto']['name'], $ext);
$imagem_nome = md5(uniqid(time())) . "." . $ext[1];
rename($_FILES['foto']['tmp_name'], "/tmp/" . $imagem_nome);
$postData = array();
$postData['fileupload'] = "@/tmp/" . $imagem_nome;
$postData['submit'] = "Submit";
$postData['key'] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$postData['rembar'] = "yes";
$postData['xml'] = "yes";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.imageshack.us/index.php");
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_TIMEOUT, 240);curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );
$response = curl_exec( $ch );
curl_close($ch );
echo $response;
?>
I did not use the $_FILES['foto']['type'] function to get the file extension, because if the file type is jpg, this function returns pjpg, generating an error of invalid format in the Imageshack.
The Imageshack then returns a xml that be parsed, with links to the image.
I have another question. When I renamed the file in the temp directory, this file will be automatic deleted or I need to delete the file manually?