PHP implements multiple image upload class examples, _PHP tutorial

PHP implements multiple image upload class examples, This article describes a practical PHP multi-image file upload class, which supports multiple image upload functions in gif, jpg, jpeg, pjpeg, and png formats. The class can also limit image types, upload image size, and set upload Directory, some submission judgment and other functions. In addition, this class is not limited to uploading images. It can also upload file types such as TXT/RAR. It just requires some modifications to the code. Interested readers can try it themselves. The complete function code of PHP multi-image upload class is as follows: handledate = date(‘m-d-Y’); if (!empty(file_name)){ this -> file_name = file_name; this -> file_error = file_error; this -> file_size = file_size; this -> file_tmp_name = file_tmp_name; this -> file_type = file_type; this -> file_type_array = array(‘/’, ‘image/gif’, ‘image/jpg’, ‘image/jpeg’, ‘image/pjpeg’, ‘image/png’); this -> file_type_real_array = array(0.1, ‘jpg’ => 74707370, ‘gif’ => 7173, ‘bmp’ => 6677, ‘png’ => 807871); this -> show_execute_message(this -> file_error, this -> file_name, this -> file_type, this -> file_size); } } function __destruct(){ this -> file_name = NULL; this -> file_error = NULL; this -> file_size = NULL; this -> file_tmp_name = NULL; this -> file_type = NULL; self :: totalsize =…

Example of how to write verification rules for uploading files in the kohana framework, _PHP tutorial

Example of writing verification rules for uploading files in the kohana framework, First let me state that I am using version ko3.2.0. Kohana’s verification is less understood by students who use it, because there are examples in the comments of each function. The situation I encountered today was to verify the upload of images, and Kohana’s example looked like this. The code is as follows: $array->rule(‘file ‘, ‘Upload::type’, array(array(‘jpg’, ‘png’, ‘gif’))); There is no problem with this in itself, but it is always a bit inconvenient in actual applications. Why? Because when it is passed to later processing, not only the upload of the image must be verified, but also certain fields of the form must be verified. Generally we will write like this The code is as follows: $post = new Validation($_POST); $file = new Validation($_FILES); There is nothing wrong with writing like this, and it is ok to write according to the example when verifying. But it feels a bit strange to use new twice, and we also know that $_POST and $_FILES are both arrays. Can we verify it at once? “Yes, of course.” , we have to turn them into a large array first. It’s OK…

Detailed explanation of ThinkPHP conventional configuration files, _PHP tutorial

Detailed explanation of ThinkPHP custom configuration files, ThinkPHP’s system has a built-in convention configuration file (Conf\convention.php located under the system directory), which configures common parameters by default according to most uses. This article comments on the conventional configuration files and explains them in detail as follows for your reference: false, // Whether to enable debugging mode ‘APP_DOMAIN_DEPLOY’ => false, // Whether to use an independent domain name to deploy the project ‘APP_PLUGIN_ON’ => false, // Whether to enable the plug-in mechanism ‘APP_FILE_CASE’ => false, // Whether to check the case of the file is valid for Windows platform ‘APP_GROUP_DEPR’ => ‘.’, // Delimiter between module groups ‘APP_GROUP_LIST’ => ”, // Project grouping settings, separate multiple groups with commas, such as ‘Home,Admin’ ‘APP_AUTOLOAD_REG’ => false, // Whether to enable SPL_AUTOLOAD_REGISTER ‘APP_AUTOLOAD_PATH’ => ‘Think.Util.’, // __autoLoad mechanism additionally detects path settings, pay attention to the search order ‘APP_CONFIG_LIST’ => array(‘taglibs’,’routes’,’tags’,’htmls’,’modules’,’actions’), // A list of additional configurations that need to be loaded by the project. The default includes: taglibs (tag library definition ), routes (route definition), tags (tag definition), (htmls) static cache definition, modules (extension module), actions (extension operation) /* COOKIE settings */ ‘COOKIE_EXPIRE’ => 3600, // Coodie validity period ‘COOKIE_DOMAIN’ => ”,…

Solution to json_encode in php to deal with gbk and gb2312 Chinese garbled problems, _PHP tutorial

Solution to json_encode in php to deal with gbk and gb2312 Chinese garbled problems, This article describes how json_encode in PHP handles gbk and gb2312 Chinese garbled problems. The specific methods are as follows: 1.json_encode() Chinese returns null for Chinese in gbk/gb2312 $arr = array ( array ( ‘catid’ => ‘4’, ‘catname’ => ‘www.jb51.net’, ‘meta_title’ => ‘Bangke’s Home’ ) ); echo json_encode($arr); Run results: [{“catid”:”4″,”catname”:”www.jb51.net”,”meta_title”:null}] Did you take a look at “meta_title”:null? It originally had a value of “Bangkezhijia”. We checked this and the principle is that json_encode only supports uft-8 encoding. Let’s convert it 2. The background PHP page (the page is encoded as UTF-8 or the characters have been converted to UTF-8) uses json_encode to convert the array array in PHP into a JSON string. For example: ‘Chinese string’,’value’=>’test’); echo json_encode($testJSON); ?> View the output results: {“name”:”u4e2du6587u5b57u7b26u4e32″,”value”:”test”} It can be seen that even if UTF8-encoded characters are used, Chinese garbled characters appear when using json_encode. The solution is to process the characters with the function urlencode() before using json_encode, then json_encode, and then use the function urldecode() to convert them back when outputting the result. The details are as follows: ‘Chinese string’,’value’=>’test’); //echo json_encode($testJSON); foreach ( $testJSON as…

Interpretation of the processing of uploaded files in PHP,_PHP Tutorial

Interpretation of the processing of uploaded files in PHP, When we edit our own information in the browser, we will encounter uploaded avatars; in the library, we will upload documents… …the word “upload” is everywhere. PHP is the best language (programmers in other languages ​​don’t hit me…). PHP has natural advantages in handling interactions, and naturally has powerful functions to process uploaded files. Like submitting general data, uploading files also requires a form. Let’s create a special form to upload files. ok, let’s analyze this code segment. The above enctype specifies what encoding format the data adopts when it is sent to the server. It has three values: The MAX_FILE_SIZE hidden field (in bytes) must be placed before the file input field, and its value is the maximum size of the file. This is a suggestion to the browser, php also checks for this. This barrier can be bypassed on the browser side though, so don’t count on using it to block large files. But the maximum value of the file is limited by post_max_size=(number)M in php.ini. But it’s better to add this item, it can save users from the trouble of finding out that the upload of large files…

MacOS installs PHP’s image cropping extension Tclip,_PHP Tutorial

MacOS installs PHP image clipping extension Tclip, Tclip is used for image clipping and has the following features: Can perform face recognition. If there is a face in the picture, it will be automatically regarded as an important area and will not be cropped. Other important areas are automatically identified. If no face is recognized in the picture, heavy regions are calculated from the feature distribution. All in all, the important areas in the picture are automatically identified, and the important areas are preserved when the picture is cropped. Source address: https://github.com/exinnet/tclip Install opencv According to the instructions on github, there is no problem with the installation on CentOS, but it hangs on my MacOS. The first problem encountered is that opencv cannot be installed. Fortunately, download the latest opencv-2.4.11 from github and install it successfully. Download address: https://github.com/Itseez/opencv/releases Use the latest version of OpenCV 2.4.11 Installation dependencies Before installing opencv, install some dependency packages first: The code is as follows: brew install gtk+ pkgconfig libpng zlib libjpeg libtiff cmake Tips: Please refer to http://brew.sh/ for installation and usage of brew Install opencv Start installing opencv: The code is as follows: tar zxf opencv-2.4.11.tar.gz cd opencv-2.4.11 cmake CMakeLists.txt make &&…

PHP implements file download,_PHP Tutorial

PHP implements file download, 1 public function get_download_file() 2 { 3 header ( ‘Content-Description: File Transfer’ ); 4 header ( ‘Content-Type: application/octet-stream’ ); 5 header ( ‘Content-Disposition: attachment; filename=’ . basename ( $file )); 6 header ( ‘Content-Transfer-Encoding: binary’ ); 7 header ( ‘Expires: 0’ ); 8 header ( ‘Cache-Control: must-revalidate’ ); 9 header ( ‘Pragma: public’ ); 10 header ( ‘Content-Length: ‘ . filesize ( $file ) ); 11 ob_clean (); 12 flush (); 13 readfile ( $file ); 14 exit; 15 } http://www.bkjia.com/PHPjc/1136182.htmlwww. bkjia.comtruehttp://www.bkjia.com/PHPjc/ 1136182.htmlTechArticlePHP implements file download, 1 public function get_download_file() 2 { 3 header ( ‘Content-Description: File Transfer’ ); 4 header ( ‘Content-Type: application/octet-stream’ ); 5 header…

File_exists() in PHP judges the solution to the invalid Chinese file name,_PHP Tutorial

The solution to judging the invalid Chinese file name by file_exists() in PHP, This article describes the solution of file_exists() in PHP to judge that the Chinese file name is invalid. Share it with everyone for your reference. The specific method is as follows: We will use the file_exists function or is_file function to judge whether a file exists in php, but when using file_exists, if your file name or path is in Chinese, it will be invalid when uft8 encodes the document. This article will solve this problem, let’s take a look together below. Definition and usage: The file_exists() function checks for the existence of a file or directory. Returns true if the specified file or directory exists, false otherwise. Example 1 The code is as follows: <?php echo file_exists(“test.txt”); ?> Output: 1 Example 2 The code is as follows: $realname=’Chinese.txt’; if(file_exists($realname)) { // never get in here } else { echo ‘www.gxlcms.com reminds you that the file does not exist’; } The output is www.gxlcms.com to remind you that the file does not exist But I was surprised that the file exists, and there is no problem with the path. The php file and the Chinese.txt are in…

A tutorial on building Nginx+PHP+MySQL development environment on MacOS,_PHP Tutorial

Tutorial to build Nginx+PHP+MySQL development environment on Mac OS, Install homebrew homebrew is a very easy-to-use package manager for mac, which will automatically install related dependent packages, freeing you from the tedious installation of software dependencies. Installing homebrew is also very simple, just enter in the terminal: ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)” Common commands of homebrew: brew update #Update the latest information of the installable package, it is recommended to run it before each installation brew search pkg_name #Search related package information brew install pkg_name #installation package For more information, see homebrew Install nginx Install brew search nginx brew install nginx The current latest version is 1.4.4. Configuration cd /usr/local/etc/nginx/ mkdir conf.d vim nginx.conf vim ./conf.d/default.conf nginx.conf content, worker_processes 1; error_log /usr/local/var/log/nginx/error.log warn; pid /usr/local/var/run/nginx.pid; events { worker_connections 256; } http { include mime.types; default_type application/octet-stream; log_format main ‘$remote_addr – $remote_user [$time_local] “$request”‘ ‘$status $body_bytes_sent “$http_referer”‘ ‘”$http_user_agent” “$http_x_forwarded_for”‘; access_log /usr/local/var/log/nginx/access.log main; port_in_redirect off; sendfile on; keepalive_timeout 65; include /usr/local/etc/nginx/conf.d/*.conf; } default.conf file content, server { listen 8080; server_name localhost; root /Users/user_name/nginx_sites/; # This item should be modified to the path where you are going to store related web pages location / { index index.php; autoindex on; } #proxy the php…

Small guestbook example of php file operation,_PHP Tutorial

Example of small guestbook for php file operation, The example in this article describes the small guestbook for php file operation. Share it with everyone for your reference. The details are as follows: The Index.php file is as follows: <?php $path = "DB/"; //Define the path $dr = opendir($path); //open directory while($filen = readdir($dr)) //loop to read the files in the directory { if($filen != "." and $filen != "..") { $fs = fopen($path. $filen, "r"); echo "Title:“.fgets($fs).”“; echo “Author:“.fgets($fs).”“; echo “Content: “.fread($fs, filesize($path.$filen)).”“; echo ““; fclose($fs); } } closedir($dr) //close directory ?> The Post.php file is as follows: Post a new message I hope that the description in this article will be helpful to everyone’s php programming design. http://www.bkjia.com/PHPjc/1019440.htmlwww. bkjia.comtruehttp://www.bkjia.com/PHPjc/ 1019440.htmlTechArticleA small guestbook example of php file operation, this article describes the example A small guestbook for php file manipulation. Share it with everyone for your reference. The details are as follows: The Index.php file is as follows: php $p…

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
首页
微信
电话
搜索