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...