In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to upload pictures in PHP". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to upload pictures on PHP".
First of all, we add the upload attachment # file and the upload button # imgbut to the form form, and remember to add multipart/form-data to the form form, otherwise you won't be able to upload the image.
Judgment of various restrictions before upload:
If ($_ FILES ["img"] ["error"] > 0) {switch ($_ FILES ["img"] ["error"]) {case 1: echo "alert ('the uploaded file exceeds the upload_max_filesize option limit in php.ini
'); history.back (); "; break; case 2: echo" alert (' the size of the uploaded file exceeds the value specified by the MAX_FILE_SIZE option in the HTML form'); history.back (); break; case 3: echo "alert ('only part of the file is uploaded'); history.back ();" Break; case 4: echo "alert ('no files were uploaded'); history.back ();"; break; default: echo "alert ('unknown error'); history.back ();";} exit;} $maxsize = 1000000 / / step 2 uses $_ FILES ["pic"] ["size"] to limit the size in bytes 2M=2000000 if ($_ FILES ["img"] ["size"] > $maxsize) {echo "alert ('the uploaded file is too large to exceed {$maxsize} bytes'); history.back ();"; exit } / / step 3 uses $_ FILES ["pic"] ["type"] or file extension restriction type MIME image/gif image/png gif png jpg $allowtype = array ("png", "gif", "jpg", "jpeg"); $arr = explode (".", $_ FILES ["img"] ["name"]); $hz = $arr [count ($arr)-1] If (! in_array ($hz, $allowtype)) {echo "alert ('this is a type not allowed'); history.back ();"; exit;}
Upload pictures:
$filepath = "uploads/"; / / to match the path of UBB $randname = date ("Y"). Date ("m") Date ("d") Date ("H") Date ("I"). Date ("s"). Rand (100999). "." $hz; / / move the files in the temporary location to the specified directory to if (is_uploaded_file ($_ FILES ["img"] ["tmp_name"]) {if (move_uploaded_file ($_ FILES ["img"] ["tmp_name"], $filepath. $randname) {echo "alert ('upload successful'); history.back ();"; session_start (); $_ SESSION ['images'] = $filepath. $randname; / / echo $_ SESSION ['images'];} else {echo "alert (' upload failed'); history.back ();";}} else {echo "alert ('not an upload file'); history.back ();" } at this point, I believe you have a deeper understanding of "how to upload pictures on PHP". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.