Results 1 to 6 of 6
Threaded View
-
31st Oct 2009, 06:50 AM #1OPRespected DeveloperWebsite's:
X4B.orgImage Upload in php. Code snippet #2
My second code snippet for the day.
Requirements:
- CURL
- PHP5
PHP Code:<?
/*
Name: Image Class
Splitice - thewarezscene.org
*/
class image{
var $login = array('user'=>false,'pass'=>false);
private $image = '';
function image($img){
$this->image=$img;
}
function upload_im4ge($image) {
$postParams = array ('v2'=>'1','image' => '@' . $image );
if($this->login['user']&&$this->login['pass']){
$postParams['login_user'] = $this->login['user'];
$postParams['login_pass'] = $this->login['pass'];
$postParams['login'] = true;
}
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, 'http://im4ge.info/api.php' );
curl_setopt ( $ch, CURLOPT_POST, true );
curl_setopt ( $ch, CURLOPT_NOPROGRESS, false );
//curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt ( $ch, CURLOPT_TIMEOUT, 0 );
curl_setopt ( $ch, CURLOPT_VERBOSE, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $postParams );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
$postResult = curl_exec ( $ch );
if (! $postResult){
curl_close($ch);
return false;
}
if (curl_errno ( $ch )) {
trigger_error ( 'Unable to upload file: ' . curl_error ( $ch ) );
curl_close($ch);
return false;
}
curl_close ( $ch );
$dd = unserialize($postResult);
return $dd;
}
function set_login($user, $pass){
$this->login['user'] = $user;
$this->login['pass'] = $pass;
}
function upload_img($nocache = false){
$i = $this->image;
if($nocache===false&&substr($i,0,7)=='http://'){
$res = mysql_query('SELECT * FROM image_cache WHERE url="'.mysql_real_escape_string($i).'"');
$row = mysql_fetch_assoc($res);
return unserialize($row['data']);
}
$size = array();
if (! strpos ( $i, '?' )) {
$p = pathinfo ( $i );
$t = tempnam ( '/tmp', 'img_' ) . '.' . $p ['extension'];
$d = file_get_contents ( trim ( $i ) );
if (! $d) {
return array(false,'image not available');
}
file_put_contents ( $t, $d );
$d = $this->upload_im4ge ( $t );
$size = getimagesize($t);
unlink($t);
if($d===false){
return array(false,'upload failed');
}
if($d['error']){
return array(false,'upload failed: '.$d['errormsg']);
}
$t = array ('url' => $i, 'bbcode' => $d );
$i = $t;
}else{
return array(false, 'dont upload');
}
if(!file_get_contents($i['bbcode']['thumbnail'])){
$i['bbcode']['thumbnail'] = $i['bbcode']['image'];
}
$ret = array('thumbnail'=>$i['bbcode']['thumbnail'],'image'=>$i['bbcode']['image'],'link'=>$i['bbcode']['url'],'width'=>$size[0],'height'=>$size[1]);
if($nocache===false&&substr($i,0,7)=='http://'){
mysql_query('INSERT INTO images_cache VALUES("'.mysql_real_escape_string($this->image).'","'.mysql_real_escape_string(serialize($ret)).'")');
}
return $ret;
}
function __toString(){
return $this->image;
}
}
?>
PHP Code:$img = new image('local or remote image');
$img->upload_img();
SplitIce Reviewed by SplitIce on . Image Upload in php. Code snippet #2 My second code snippet for the day. Requirements: - CURL - PHP5 <? /* Name: Image Class Rating: 5
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
How to code image in css and se in wordpress post?
By BattleDuty in forum WordpressReplies: 4Last Post: 14th Mar 2012, 11:54 AM -
[Hiring] code for Right click Image uploader
By cool.guy.prince in forum Completed TransactionsReplies: 2Last Post: 26th Jun 2011, 05:44 AM -
i need filesonic php upload code
By chems in forum Web Development AreaReplies: 26Last Post: 20th Feb 2011, 07:28 PM -
Insert Image Code
By warezboy in forum vBulletinReplies: 12Last Post: 9th Jun 2010, 06:16 PM -
Insert Image CODE
By tom247 in forum Web Application/Script SupportReplies: 3Last Post: 9th Jun 2010, 05:04 AM
themaCreator - create posts from...
Version 3.08 released. Open older version (or...