Php image uploading client and server implementation method, _ PHP Tutorial

Source: Internet
Author: User
Php implements Image uploading on the client and server ,. Php image uploading client and server implementation method. This article describes how php uploads image clients and servers. Share it with you for your reference. The specific steps are as follows: the implementation of the client and server for uploading images in php before,

This example describes how to upload images to the client and server in php. 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.

Example: This article describes how to upload images to the client and server in php. Share it with you for your reference. The details are as follows...

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.