Php image uploading client and server implementation

Source: Internet
Author: User
This article mainly introduces the implementation of php image uploading client and server. it involves php file operation skills, and common methods such as image suffix verification and file rename. it has some reference value, for more information about how to upload an image client and a server in php, see the following example. Share it with you for your reference. The details are as follows:

Front-end form code

 

Backend php code

<? Php // Upload $ upsize here to determine the size of the uploaded file $ uppath = "/attached/"; // file Upload path // Convert the root directory path if (strpos ($ uppath, "/") = 0) {$ I = 0; $ thpath = $ _ SERVER ["SCRIPT_NAME"]; $ thpath = substr ($ thpath, 1, strlen ($ thpath); while (strripos ($ thpath ,"/")! = False) {$ thpath = substr ($ thpath, strpos ($ thpath, "/") + 1, strlen ($ thpath )); $ I = ++ $ I;} $ pp = ""; for ($ j = 0; $ j <$ I; ++ $ j) {$ pp. = ".. /";}$ uppaths = $ pp. substr ($ uppath, 1, strlen ($ thpath);} $ filename = date ("y-m-d"); if (is_dir ($ uppaths. $ filename )! = TRUE) mkdir ($ uppaths. $ filename, 0777); $ f = $ _ FILES ['Pic ']; if ($ f ["type"]! = "Image/gif" & $ f ["type"]! = "Image/pjpeg" & $ f ["type"]! = "Image/jpeg" & $ f ["type"]! = "Image/x-png") {echo "script" alert ('only images can be uploaded '); window. close () script "; return false;} // get the file extension $ temp_arr = explode (". ", $ f [" name "]); $ file_ext = array_pop ($ temp_arr); $ file_ext = trim ($ file_ext); $ file_ext = strtolower ($ file_ext ); // new file name $ new_file_name = md5 (date ("YmdHis ")). '. '. $ file_ext; echo $ dest = $ uppaths. $ filename. "/". date ("ymdhis "). "_". $ new_file_name; // Set the file name to the date plus the file name to avoid repeated Upload directory ec Ho $ dest1 = $ uppath. $ filename. "/". date ("ymdhis "). "_". $ new_file_name; // Set the file name to the date plus the file name to avoid duplication. $ r = move_uploaded_file ($ f ['tmp _ name'], $ dest);?>

I hope this article will help you with php programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.