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.