-
- /**
- 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
|