Simple example of uploading and deleting images in php
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-25 09:04:05
Original
898 people have browsed it
-
- /**
- php upload pictures
- link: http://bbs.it-home.org
- */
- if (!empty($_FILES["img"]["name"])) { //Extract the file domain content name and judge
- $path="uppic/"; //Upload path
- if(!file_exists($path))
- {
- //Check whether the folder exists, if not, create it and give it the highest permissions
- mkdir("$path" , 0700);
- }//END IF
- //File formats allowed to be uploaded
- $tp = array("image/gif","image/pjpeg","image/jpeg");
- //Check whether the uploaded file is In the types that are allowed to be uploaded
- if(!in_array($_FILES["img"]["type"],$tp))
- {
- echo “<script>alert('Incorrect format');history.go(- 1);</script>”;
- exit;
- }//END IF
- $filetype = $_FILES['img']['type'];
- if($filetype == 'image/jpeg'){
- $type = '.jpg';
- }
- if ($filetype == 'image/jpg') {
- $type = '.jpg';
- }
- if ($filetype == 'image/pjpeg') {
- $type = '.jpg';
- }
- if($filetype == 'image/gif'){
- $type = '.gif';
- }
- if($_FILES["img"]["name" ])
- {
- $today=date(“YmdHis”); //Get the time and assign it to the variable
- $file2 = $path.$today.$type; //The full path of the image
- $img = $today.$ type; //Picture name
- $flag=1;
- }//END IF
- if($flag) $result=move_uploaded_file($_FILES["img"]["tmp_name"],$file2);
- //Special Note that the first parameter passed to move_uploaded_file here is the temporary file uploaded to the server
- }//END IF
- //Then write the value of $img to the corresponding field in the database
- ?>
Copy Code
2. Delete pictures:
-
- $img = //Query the database to find the corresponding data value
- unlink("uppic/".$img); //Delete the file
- ?>
-
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2025-02-26 03:58:14
-
2025-02-26 03:38:10
-
2025-02-26 03:17:10
-
2025-02-26 02:49:09
-
2025-02-26 01:08:13
-
2025-02-26 00:46:10
-
2025-02-25 23:42:08
-
2025-02-25 22:50:13
-
2025-02-25 21:54:11
-
2025-02-25 20:45:11
Latest Issues
-
2025-03-26 19:56:00
-
2025-03-26 19:55:08
-
2025-03-26 19:52:08
-
2025-03-26 19:51:12
-
2025-03-26 19:50:14