php+curl ·¢ËÍͼƬ´¦Àí´úÂë·ÖÏí

5年以前  |  阅读数:777 次  |  编程语言:PHP 

//ÉÏ´«Ò³Ãae´uÂe


      $url = "http://192.168.1.100/upload.php?lang=cn";  #¿ÉÒÔget´«ÏaÓ¦²ÎÊý
      $file = $path.'/'. $Icon; //ÒªÉÏ´«µÄÎļþ
      $fields['f'] = '@'.$file;
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, $url );
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
      curl_setopt($ch, CURLOPT_POST, 1 );
      curl_setopt($ch, CURLOPT_POSTFIELDS, $fields );
      curl_exec( $ch );
      if ($error = curl_error($ch) ) {
        die($error);
      }
      curl_close($ch); 
//½ÓÊÕͼƬ×ÊÔ´  

      date_default_timezone_set('Asia/Shanghai'); //ÉeÖÃʱÇø
      $ip = '';
      if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')){
            $ip = getenv('HTTP_CLIENT_IP');
        }elseif(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')){
            $ip = getenv('HTTP_X_FORWARDED_FOR');
        }elseif(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')){
            $ip = getenv('REMOTE_ADDR');
        }elseif(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')){
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        preg_match("/[\d\.]{7,15}/", $ip, $ipmatches);
        $ip = $ipmatches[0] ? $ipmatches[0] : 'unknown';

        //ož×CÕˆÇoIP,ÉeÖð×Ãuµ¥
        $date = date("[Y-m-d H:i:s]");
        $allowip = array('192.168.1.100');
        if(!in_array($ip,$allowip)){
            $ipVal = "{$date}{$ip}\n";
            file_put_contents('upload_ip.log', $ipVal, FILE_APPEN);
            die(-1);
        }

        //½ÓÊÕget´«²Î
        $lang = isset($_REQUEST['lang']) ? $_REQUEST['lang'] : 'CN'; 
        $uploaddir = "/data/cdncache/res/gifts/{$lang}/";
        $uploadfile = $uploaddir . $_FILES['f']['name'];
        if (move_uploaded_file($_FILES['f']['tmp_name'], $uploadfile)) #±£´aeͼƬ³É¹¦
        {
            $type = $_FILES['f']['type'];
            $tmp_name = $_FILES['f']['tmp_name'];
            $error = $_FILES['f']['error'];
            $size = $_FILES['f']['size'];
            $log_txt = ' name:' . $_FILES['f']['name'] . ' type:' . $type . ' tmp_name:' . $tmp_name . ' error:' . $error . ' size:' . $size . " hello " . ' lang:' . $_REQUEST['lang'];
            $value = "{$date}{$log_txt}\n";
            @file_put_contents('upload_ok.log', $value, FILE_APPEND);
            exit();
        } else {
            $type = $_FILES['f']['type'];
            $tmp_name = $_FILES['f']['tmp_name'];
            $error = $_FILES['f']['error'];
            $size = $_FILES['f']['size'];
            $log_txt = ' name:' . $_FILES['f']['name'] . ' type:' . $type . ' tmp_name:' . $tmp_name . ' error:' . $error . ' size:' . $size . " hello " . ' lang:' . $_REQUEST['lang'];
            $value = "{$date}{$log_txt}\n";
            @file_put_contents('upload_ng.log', $value, FILE_APPEND);
            exit();
      }

ÒÔÉÏËuÊo¾ÍÊDZ¾ÎĵÄÈ«²¿ÄÚÈÝÁË£¬Ï£Íu´o¼ÒÄܹ»Ï²»¶¡£

 相关文章:
PHP分页显示制作详细讲解
SSH 登录失败:Host key verification failed
获取IMSI
将二进制数据转为16进制以便显示
获取IMEI
贪吃蛇
文件下载
双位运算符
发送邮件
PHP自定义函数获取搜索引擎来源关键字的方法
Java生成UUID
提取后缀名
年的日历图
在Zeus Web Server中安装PHP语言支持
让你成为最历害的git提交人
Yii2汉字转拼音类的实例代码
再谈PHP中单双引号的区别详解
指定应用ID以获取对应的应用名称
Python 2与Python 3版本和编码的对比
php封装的page分页类完整实例