This article introduces a simple php file Upload sample code for beginners. if you need to learn more, refer to. the instance code is as follows :? Php definition prompt function functionaler... this article will introduce you to a simple php file Upload sample code for beginners. if you need to learn, visit the reference.
The instance code is as follows:
Alert ("'. $ msg. '"); window. history. back (-1); script ';} // defines the allowed file types $ allowType = array ('image/jpeg', 'image/GIF ', 'image/jpg '); // defines the path, which can be an absolute path or a relative path $ filePath = '. /uploadFileDir/'; // The file value written in the received form information is the name value in the form of the static page $ file =$ _ FILES ['file']; // Step 1: Determine whether the uploaded file has an error if ($ file ['error']! = 0) {exit (alert ('file Upload error');} // Step 2: determine the file size. here, 102400 is the byte, converting to kb is 100 kbif ($ file ['size']> 102400) {exit (alert ('file too large ');} // Step 3, determine the file type if (! In_array (mime_content_type ($ file ['tmp _ name']), $ allowType) {exit (alert ('file type error');} // Step 4, determine whether the path exists. if not, create if (! File_exists ($ filePath )&&! Mkdir ($ filePath, 0777, true) {exit (alert ('directory creation error');} // Step 5, defines the name and path of the uploaded file $ filename = time (). '_'. $ file ['name']; // Step 6: Copy the object if (! Copy ($ file ['tmp _ name'], $ filePath. $ filename) {exit (alert ('file Upload error, please try again later ');} // Step 7, delete the temporary file unlink ($ file ['tmp _ name']); // the system prompts that the upload is successful echo alert ('Congratulations, upload file ['. $ filename. '] successful! ');?>
Tutorial URL:
You are welcome to add your _ favorites to the Favorites folder, but please keep the link for this article.