Php image uploading client and server implementation,
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
<Form name = "form1" method = "post" action = "admin_upfile.php" enctype = "multipart/form-data"> <input type = "file" name = "pic"> <input type = "submit" name = "Submit" value = "Start upload" class = "button"> </form>
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;} // obtain 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 e Cho $ 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.