Качване на снимка на хост и вземане на линкове

HunteR каза:
Ето какво намерих.
http://www.phpclasses.org/browse/package/3753.html

С малко преработка ще стане муцка :P
Аз ползвам този клас за да качвам в prikachi.com за lxshot :)
Там се взима най-лесно линка после
 
alex95_bg_2 каза:
HunteR каза:
Ето какво намерих.
http://www.phpclasses.org/browse/package/3753.html

С малко преработка ще стане муцка :P
Аз ползвам този клас за да качвам в prikachi.com за lxshot :)
Там се взима най-лесно линка после

и как да го направя за да качва в picbg?

Код:
<?php
/**************************************************************************************
Author:  Abhishek Kumar Srivastava
Email:     abhisheksrivastava@fastmail.fm
Purpose: The class is written for uploading file using curl
Liscense: GNU GPL
**************************************************************************************/

class CurlFileUploader {
	var $filePath;
	var $uploadURL;
	var $formFileVariableName;
	var $postParams = array();
	
	/* Constructor for CurlFileUploader
	* @param $filePath absolute path of file
	* @param $uploadURL url where you want to upload file
	* @param $formFileVariableName form field name to upload file
	* @param $otherParams assosiative array of other params which you want to send as post
	*/ 
	function CurlFileUploader ($filePath, $uploadURL, $formFileVariableName, /* assosiative array */ $otherParams = false) {
		$this->filePath = $filePath;
		$this->uploadURL = $uploadURL;
		if(is_array($otherParams) && $otherParams != false) {
			foreach ($otherParams as $fieldName => $fieldValue) {
				$this->postParams[$fieldName] = $fieldValue;
			}
		}
		$this->postParams[$formFileVariableName] = "@".$filePath;
		
	}
	
	/*
	* function to upload file
	* if unable to upload file produce error and exit
	* else upload file
	*/
	function UploadFile () {
   		$ch = curl_init();
   		curl_setopt($ch, CURLOPT_URL, $this->uploadURL );
   		curl_setopt($ch, CURLOPT_POST, 1 );
   		print_r($this->postParams);
   		curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postParams);
   		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   		$postResult = curl_exec($ch);

   		if (curl_errno($ch)) {
       		print curl_error($ch);
       		print "<br>Unable to upload file.";
       		exit();
   		}
   		curl_close($ch);
		exit();
	}
}
?>
 
Код:
<?php
/**************************************************************************************
Author:  Abhishek Kumar Srivastava
Email:     abhisheksrivastava@fastmail.fm
Purpose: The class is written for uploading file using curl
Liscense: GNU GPL
**************************************************************************************/

class CurlFileUploader {
    var $filePath;
    var $uploadURL;
    var $formFileVariableName;
    var $postParams = array();
    
    /* Constructor for CurlFileUploader
    * @param $filePath absolute path of file
    * @param $uploadURL url where you want to upload file
    * @param $formFileVariableName form field name to upload file
    * @param $otherParams assosiative array of other params which you want to send as post
    */ 
    function CurlFileUploader ($filePath, $uploadURL, $formFileVariableName, /* assosiative array */ $otherParams = false) {
        $this->filePath = $filePath;
        $this->uploadURL = $uploadURL;
        if(is_array($otherParams) && $otherParams != false) {
            foreach ($otherParams as $fieldName => $fieldValue) {
                $this->postParams[$fieldName] = $fieldValue;
            }
        }
        $this->postParams[$formFileVariableName] = "@".$filePath;
        
    }
    
    /*
    * function to upload file
    * if unable to upload file produce error and exit
    * else upload file
    */
    function UploadFile () {
           $ch = curl_init();
           curl_setopt($ch, CURLOPT_URL, $this->uploadURL );
           curl_setopt($ch, CURLOPT_POST, 1 );
           #print_r($this->postParams);
           curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postParams);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
           $postResult = curl_exec($ch);

           if (curl_errno($ch)) {
               #print curl_error($ch);
               print "<br>Unable to upload file.";
               exit();
           }
           
           /*
           ТУК ТВОЯ КОД
           променливата $postResult ще ти върне страницата в която вече са качени картинките със всички линкове. Твоята задача е просто чрез explode примерно да отделиш това, което ти трябва от тази променлива :)
           */
           
           curl_close($ch);
        exit();
    }
}

$objCurlFileUploader = new CurlFileUploader("D:\\My Pic\\my_pic.jpg", "http://pic-bg.net/upload.php",'userfile[]');
$objCurlFileUploader->UploadFile();
?>
D:\\My Pic\\my_pic.jpg е снимката, която ще качваш :)
 
Аз качвам с прикачи с този код :)

Код:
<?php
error_reporting(E_ALL);

class CurlFileUploader {
    var $filePath;
    var $uploadURL;
    var $formFileVariableName;
    var $postParams = array();
    
    /* Constructor for CurlFileUploader
    * @param $filePath absolute path of file
    * @param $uploadURL url where you want to upload file
    * @param $formFileVariableName form field name to upload file
    * @param $otherParams assosiative array of other params which you want to send as post
    */ 
    function CurlFileUploader ($filePath, $uploadURL, $formFileVariableName, /* assosiative array */ $otherParams = false) {
        $this->filePath = $filePath;
        $this->uploadURL = $uploadURL;
        if(is_array($otherParams) && $otherParams != false) {
            foreach ($otherParams as $fieldName => $fieldValue) {
                $this->postParams[$fieldName] = $fieldValue;
            }
        }
        $this->postParams[$formFileVariableName] = "@".$filePath;
        
    }
    
    /*
    * function to upload file
    * if unable to upload file produce error and exit
    * else upload file
    */
    function UploadFile () {
           $ch = curl_init();
           curl_setopt($ch, CURLOPT_URL, $this->uploadURL );
           curl_setopt($ch, CURLOPT_POST, 1 );
           //print_r($this->postParams);
           curl_setopt($ch, CURLOPT_POSTFIELDS, $this->postParams);
           curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
           $postResult = curl_exec($ch);

				

           if (curl_errno($ch)) {
               print curl_error($ch);
               print "<br>Unable to upload file.";
               exit();
           }
           curl_close($ch);
           return $postResult;
        //exit();
    }
} 



//print_r($_FILES['file1']);

$tmp = $_FILES['file1']['tmp_name'];

//if (@exif_imagetype($tmp) != IMAGETYPE_PNG) die("lxshot server: bad request");

if($_FILES['file1']['size'] > 2097152) die("lxshot server: image too big. sorry, max 2mb"); //2mb

$name = "shots/".md5(uniqid(rand(), true)).".png";

move_uploaded_file($_FILES['file1']['tmp_name'], $name);


$objCurlFileUploader = new CurlFileUploader($name, "http://www.prikachi.com/index.php",'userfile1', Array('tags' => 'lxshots', 'lock' => 'Checked', 'sent' => 'Качи'));
$out = $objCurlFileUploader->UploadFile(); 


preg_match('/value="http:\/\/prikachi.com\/files\/(.*).png"/i', $out, $ret);
$id = $ret[1];

echo "http://prikachi.com/files/$id.png\n";

unlink($name);

?>

Сигурно можеш да си го промениш :)
Защото сега на него му се подава файл, той го записва временно на диска, качва го в прикачи и го изтрива :)
 

Back
Горе