upload help

ok this is what i want to have:
ill offer images(they will be saved in photobucket) & below it there’ll be a grab button.

if the visitor want the image he/she just press the button & the image will be uploaded directly to imageshack&will show the code under the image…

how do i do that?

heres the imageshack code if u need one:

http://reg.imageshack.us/content.php?pa … 090d46f02b

or:

[code]<?php

//specify either ‘post’ upload OR upload of a ‘file’ on webserver:
$uploadType = ‘file’;

if($uploadType == “post”){

/* Sample upload form to use:
	<form method="post" action="xmlapi.php" enctype="multipart/form-data">
	<input type="hidden" name="MAX_FILE_SIZE" value="1048576">
	<input type="file" name="fileupload" size="30">
	<input style="width: 100px;" type="submit" value="host it!" >
	</form>
*/

if(!$_FILES[fileupload]){ exit; }
$source = $_FILES[fileupload][tmp_name];
$dest = '/tmp/'.$_FILES[fileupload][name];
copy($source,$dest);
$xmlString = uploadToImageshack($dest);
unlink($source); unlink($dest);

} elseif($uploadType == “file”){

//specify location of file
$dest = ‘/home/image/www/creative.jpg’;
$xmlString = uploadToImageshack($dest);

}

//begin parsing xml data

if ($xmlString == ‘failed’) { echo “XML return failed”; exit; }

$xmlData = explode(“n”,$xmlString);

foreach($xmlData as $xmlDatum){

$xmlDatum = trim($xmlDatum);

if($xmlDatum != "" && !eregi("links",$xmlDatum) && !eregi("xml",$xmlDatum)){

	$xmlDatum = str_replace(">","<",$xmlDatum);
	list($xmlNull,$xmlName,$xmlValue) = explode("<",$xmlDatum);
	$xmlr[$xmlName] = $xmlValue;

}

}

/-----------------------------------------------------------------------------
available variables:
image_link: link to image, like: http://img214.imageshack.us/img214/7053/creative0cj.jpg
thumb_link: link to image thumbnail, like: http://img214.imageshack.us/img214/7053/creative0cj.th.jpg
ad_link: link to imageshack page on which image is displayed, like: http://img214.imageshack.us/my.php?image=creative0cj.jpg
thumb_exists: specifies whether thumb exists, either ‘yes’ or ‘no’
total_raters: specifies how many people rated image, numerical string
ave_rating: specifies the average rating value, numericl string between 1 and 10
image_location: internal-style link to image, like: img214/7053/creative0cj.jpg
thumb_location: internal-style link to image thumbnail, like: img214/7053/creative0cj.th.jpg
server: server name on which image resides, like: img214
image_name: filename of image after it has been uploaded, like: creative0cj.jpg
done_page: link to imageshack page on which users can get linking code, like: http://img214.imageshack.us/content.php?page=done&l=img214/7053/creative0cj.jpg
resolution: pixel resolution of image, like: 300x250
------------------------------------------------------------------------------
/

//sample return
echo ‘Upload successful!


<a href="’.$xmlr[“ad_link”].’"><img src="’.$xmlr[“thumb_link”].’" border=“0” />



Resolution: ‘.$xmlr[“resolution”].’.’;

//two functions, one for uploading from from file, the other for uploading from url, editing below this line advised only to those who know what they are doing :slight_smile:

    function uploadToImageshack($filename) {
            $ch = curl_init("http://www.imageshack.us/index.php");

            $post['xml']='yes';
            $post['fileupload']='@'.$filename;

            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, $post);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));

            $result = curl_exec($ch);
            curl_close($ch);

            if (strpos($result, '<'.'?xml version="1.0" encoding="iso-8859-1"?>') === false) {
                    return 'failed';
            } else {
                    return $result; // XML data
            }
    }

    function uploadURLToImageshack($url) {
            $ch = curl_init("http://www.imageshack.us/transload.php");

            $post['xml']='yes';
            $post['url']=$url;

            curl_setopt($ch, CURLOPT_POST, true);
            curl_setopt($ch, CURLOPT_HEADER, false);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($ch, CURLOPT_TIMEOUT, 60);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect: '));

            $result = curl_exec($ch);
            curl_close($ch);

            if (strpos($result, '<'.'?xml version="1.0" encoding="iso-8859-1"?>') === false) {
                    return 'failed';
            } else {
                    return $result; // XML data
            }
    }

[/code]

thanks to those who can help :D

Sponsor our Newsletter | Privacy Policy | Terms of Service