Example of remote image download using gd library in PHP, _PHP tutorial

Example of remote image download using gd library in PHP, _PHP tutorial

An example of using the gd library in PHP to implement remote image downloading. Because today I want to write a class for remote image downloading, so I warmed up in advance and wrote a PHP gd library to implement the remote image downloading function. Of course, the curl implementation is better. The PHP gd library implements the remote image download function. It mainly uses the two functions of the gd library, ImageCreateFromXXX(), to generate image functions and ImageXXX functions. XXX represents the extensions of different images, so you have to find a way to obtain remote images. extension, the php code is attached as follows: <?php header("Content-type:text/html; charset=utf-8"); if (!empty($_POST['submit'])){ $url = $_POST['url']; $pictureName = $_POST['pictureName']; $img = getPicture($url,$pictureName); echo ' ‘; } function getPicture($url,$pictureName){ if ($url == “”) return false; //Get the extension of the image $info = getimagesize($url); $mime = $info[‘mime’]; $type = substr(strrchr($mime,’/’), 1); //Select different image generation and saving functions for different image types switch($type){ case ‘jpeg’: $img_create_func = ‘imagecreatefromjpeg’; $img_save_func = ‘imagejpeg’; $new_img_ext = ‘jpg’; break; case ‘png’: $img_create_func = ‘imagecreatefrompng’; $img_save_func = ‘imagepng’; $new_img_ext = ‘png’; break; case ‘bmp’: $img_create_func = ‘imagecreatefrombmp’; $img_save_func = ‘imagebmp’; $new_img_ext = ‘bmp’; break; case ‘gif’: $img_create_func =…

PHP encryption and decryption string functions, _PHP tutorial

PHP encryption and decryption string functions, _PHP tutorial

PHP encryption and decryption string functions, PHP encryption and decryption string functions often used in programs The code is as follows: /****************************************** **************************** Function name:encrypt Function: Encrypt and decrypt strings Instructions: Encryption:encrypt(‘str’,’E’,’nowamagic’); Decryption:encrypt(‘encrypted string’,’D’,’nowamagic’); Parameter Description: $string: The string that needs to be encrypted and decrypted $operation: Determine whether to encrypt or decrypt: E: Encryption D: Decryption $key: Encrypted key (key); http://www.cnblogs.com/roucheng/ *************************************************** *******************/ function encrypt($string,$operation,$key=”) { $key=md5($key); $key_length=strlen($key); $string=$operation==’D’?base64_decode($string):substr(md5($string.$key),0,8).$string; $string_length=strlen($string); $rndkey=$box=array(); $result=”; for($i=0;$i<=255;$i++) { $rndkey[$i]=ord($key[$i%$key_length]); $box[$i]=$i; } for($j=$i=0;$i<256;$i++) { $j=($j+$box[$i]+$rndkey[$i])%256; $tmp=$box[$i]; $box[$i]=$box[$j]; $box[$j]=$tmp; } for($a=$j=$i=0;$i<$string_length;$i++) { $a=($a+1)%256; $j=($j+$box[$a])%256; $tmp=$box[$a]; $box[$a]=$box[$j]; $box[$j]=$tmp; $result.=chr(ord($string[$i])^($box[($box[$a]+$box[$j])%256])); } if($operation=='D') { if(substr($result,0,8)==substr(md5(substr($result,8).$key),0,8)) { return substr($result,8); } else { return''; } } else { return str_replace('=','',base64_encode($result)); } } How to use: $id = 132; $token = encrypt($id, ‘E’, ‘a’); echo ‘Encryption:’.encrypt($id, ‘E’, ‘a’); echo ”; echo ‘Decryption:’.encrypt($token, ‘D’, ‘a’); http://www.bkjia.com/PHPjc/1084381.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1084381.htmlTechArticlePHP’s encryption and decryption string functions. The PHP encryption and decryption string function codes often used in programs are as follows: /**************************** ********************************************** Letter…

Analysis of related PHP functions for writing custom storage fields in WordPress, _PHP tutorial

Analysis of related PHP functions for writing custom storage fields in WordPress, _PHP tutorial

Related PHP function analysis for writing custom storage fields in WordPress. The custom fields of WordPress are the meta information (meta information) of the article. Using this function, you can expand the article’s Function is essential knowledge for learning WordPress plug-in development and theme in-depth development, making it convenient to store some additional customized content for articles. Custom fields are not only used by plug-in developers. Information about WordPress’s featured images, custom page templates and other functions are stored in the form of custom fields. The “Custom Column” section in the article editor interface can manage fields except for fields whose names begin with “_” (if there is no “Custom Column” section, please turn it on in the “Display Options” in the upper right corner), so many WordPress itself The custom fields used cannot be managed here. Storage Principles Custom fields are very flexible. First, let’s talk about its storage principle and why it is so flexible. In the database, the wp_posts form that stores articles has only the default 20 items, which are used to store necessary article information. The wp_postmeta table that stores custom fields has only four items, namely meta_id (the ID of the custom field), post_id…

Newbie learns PHP, Chinese name: Newbie learns to shoot pornographic films, haha, I don’t know if it will be blocked, the first night, _PHP tutorial

Newbie learns PHP, Chinese name: Newbie learns to shoot pornographic films, haha, I don’t know if it will be blocked, the first night, _PHP tutorial

Newbies learn PHP, Chinese name: Newbies learn to make pornographic films, haha, I don’t know if it will be blocked, on the first night Life is inevitably boring, for those who are about to graduate Let me tell you. Majoring in .net, it is very convenient to develop things with Microsoft, but the code also needs a change of taste, and it can add a brick to the resume. Rookie, you can yell. Mian. Let’s change the topic, let’s continue talking about PHP. Since we have the foundation for learning .net before, learning PHP is very simple for beginners. The first thing we know is how to install the environment 1. Installation environment wamp (window Apache mysql php) is an integrated environment. If you are a novice, the integrated development environment can be installed quickly. It will help you install and deploy the PHP environment, mysql, etc., so you don’t need to separate it. Of course, you can try it. Install Mysql separately. I haven’t installed it separately yet~~. The WAMP integrated environment can be downloaded from Baidu in one click. The system is Windows. The integrated environment is easy to install. The next step will be ok, and then…

PHP regular method to get all image addresses on the page, _PHP tutorial

PHP regular method to get all image addresses on the page, _PHP tutorial

PHP regular method to obtain all image addresses on the page, <?php //Get all image addresses on the page function getimages($str) { $match_str = "/((http://)+([^ rn()^$!`"'|[]{}]*)((.gif)|(.jpg)|(.bmp) |(.png)|(.GIF)|(.JPG)|(.PNG)|(.BMP)))/”; preg_match_all ($match_str,$str,$out,PREG_PATTERN_ORDER); return $out; } ?> /“‘s]*)/i , I use kindeditor to save the article, but I need to take out the address of the Nth picture as the logo picture of the article. The article code (html of the content) is saved to a field in the database, and then the picture address is saved to another field. I just use Solved by the above regular rules. Let me explain that the above address is to directly obtain the value of the src attribute in the img tag. If you can access the path on the php page using this regular expression, you can use it directly. If not, you can use preg_match_all to match all The address is first saved into an array, and then the path is processed, such as getting the file name (without the path part), then reorganizing the url, and then deleting the image. My example: preg_match_all(“/”‘s]*)/i”,str_ireplace(“\”,””,$content) ,$arr); Haha, part of my content has been escaped by PHP, so I need to remove it first, str_ireplace(“\”,””,$content), and…

ThinkPHP file upload example tutorial, _PHP tutorial

ThinkPHP file upload example tutorial, _PHP tutorial

ThinkPHP file upload tutorial, File uploading is a common function in many PHP program projects. Today, this article will share a complete example to implement the ThinkPHP file uploading function. The specific methods are as follows: 1. Action part: FileAction.class.php page code is as follows: select(); $this->assign(‘filelist’,$list); $this->display(); } function upload(){ //Submit the file upload address to him, and return a message after the upload is completed to write it to the database if(empty($_FILES)){ $this->error(‘Must choose to upload file’); }else{ $a=$this->up(); if(isset($a)){ //Custom c method to write to the database if($this->c($a)){ $this->success(‘Upload successful’); } else{ $this->error(‘Failed to write to database’); } }else{ $this-error(‘Unexpected file upload, please contact the system administrator’); } } } private function c($data){ $file=M(‘file’); $num = ‘0’; for($i = 0; $i data($data)->add()) { $num++; } } if($num==count($data)-1) { return true; }else { return false; } } private function up(){ //Complete the call to the file upload class related to thinkphp import(‘@.Org.UploadFile’);//Copy the upload class UploadFile.class.php to the Lib/Org folder $upload=new UploadFile(); $upload->maxSize=’1000000′;//The default is -1, no limit on upload size $upload->savePath=’./Public/Upload/’;//It is recommended to save the path in the same directory as the main file or in a subdirectory of the same directory. $upload->saveRule=uniqid;//File name saving rules…

Analogy of the main functions of regular expressions in POSIX style and compatible Perl style (preg_match, preg_replace, _PHP tutorial

First, let’s take a look at the two main functions of POSIX-style regular expressions: ereg function: (regular expression matching) Format: int ereg ( string pattern, string string [, array &regs ] ) Note: The preg_match() function using Perl-compatible regular expression syntax is often a faster alternative to ereg(). (Generally speaking, it is better to use preg_match(), which is better~~) Find the substring matching the given regular expression pattern in string in a case-sensitive manner. If a substring is found that matches the subpattern enclosed in parentheses in pattern and the function call is given the third argument regs, the match will be stored in the regs array. $regs[1] contains the substring starting with the first left parenthesis, $regs[2] contains the second substring, and so on. $regs[0] contains the entire matched string. Return value: If a match of the pattern pattern is found in string, the length of the matched string is returned. If no match is found or an error occurs, FALSE is returned. If the optional parameter regs is not passed in or the length of the matched string is 0, this function returns 1. Let’s take a look at an example of the ereg() function: The following code…

A brief analysis of PHP bitwise AND or (^, &)_PHP tutorial

Today, a friend in the friend group asked about bitwise AND or. . I have been working in PHP for 1 year, so I may not be familiar with this part. Here I would like to introduce this part to my novice friendsPressing is mainly for binary number operations. The code is as follows: <?php$a = 1;$b = 2;$c = $a^b;echo $ c // 3?> This is not a simple addition relationship Decimal 1 is converted into binary 00000001 Decimal 2 is converted into binary 00000010 Bitwise^ 00000011 // Even if they are different, they are counted as 1^_^ Then, The code is as follows: <?php $a = 1; $b = 2; echo $a & $c; // 1 ?> Decimal 3 is converted to binary 00000011Decimal 1 Convert to binary 00000001Bitwise & 00000001 // Each digit is the same, otherwise it will be counted as 0Finally, let’s introduce the usage; the return value after bitwise& is meaningless. Mainly used to determine whether $a exists in $c // There are many permission usages. The code is as follows: <?php$my_privilege = 15; // 1+2+4+8 has all permissions$Pri = ”; $privilege_arr = array(8=>’Add’, 4=>’Delete’, 2=>’Change’, 1=>’Check’);foreach($privilege_arr as $k =>$v){ $k & $my_privilege &&…

PHPExcel operates xls files, _PHP tutorial

PHPExcel operates xls files. There will be problems reading Chinese xls and csv files. I searched for information online and found that the PHPExcel class library is easy to use. The official website address is: http:/ /phpexcel.codeplex.com/ 1. Read the contents of the xls file <?php //Read xls header(“Content-Type:text/html;charset=utf-8″); include ‘Classes/PHPExcel.php’; include ‘Classes/PHPExcel/IOFactory.php’; function readxls($file, $type) { $xlsReader = PHPExcel_IOFactory::createReader($type); $xlsReader->setReadDataOnly(true); $xlsReader->setLoadSheetsOnly(true); $sheets = $xlsReader->load($file); $content = $sheets->getSheet(0)->toArray(); //Read the A worksheet (note that the number starts from 0). If you read multiple times, you can do a loop of 0,1,2,3…. //Get a two-dimensional array. Each small array is a row of the excel table content, which contains the data of each column of this row return $content; } //$type = ‘Excel2007’; //Set the Excel type to be parsed Excel5 (2003 or below) or Excel2007 $type = ‘Excel5’; $content = readxls(‘data.xls’, $type); echo ”; var_dump($content); echo ‘ ‘; ?> 2. Write content to xls file <?php //Write content to xls file error_reporting(E_ALL); ini_set(‘display_errors’, TRUE); include ‘Classes/PHPExcel.php’; include ‘Classes/PHPExcel/IOFactory.php’; //$data:xls file content text //$title: xls file content title //$filename: exported file name //$data and $title must be utf-8 code, otherwise the FALSE value will be written function write_xls($data=array(), $title=array( ), $filename=’report’){…

PHP+iFrame implements asynchronous file upload without page refresh, _PHP tutorial

PHP+iFrame implements asynchronous file upload without page refresh, _PHP tutorial

PHP+iFrame implements asynchronous file upload without page refresh, The example in this article describes PHP+iFrame’s implementation of asynchronous file upload without page refresh, which is a very practical and common technique. Share it with everyone for your reference. The specific analysis is as follows: Speaking of iframe, fewer and fewer people use it now, and many people believe that it should be replaced by AJAX. This is true, because AJAX is so good. However, there is one situation where I still choose iframe for implementation. This is the asynchronous upload of files that this article is about. If you are interested, you can try it. If you use native AJAX to implement it, it should be much more complicated. First, let’s provide beginners with basic knowledge: 1. The iframe tag usually specifies its name attribute for identification; 2. Determine the submission destination through action (target address) and target (target window, default is _self) in the form; 3. Point the target in the form to the name of the iframe, and the form can be submitted to the hidden frame iframe; 4. The content in the iframe is actually a page, and the parent object in js refers to the parent…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索