Php supports uploading images .? Phpclassupphoto {public $ previewsize0.125; ratio of preview images public $ preview0; whether to generate preview; 1; 0 public $ datetime; random number public $ ph_name; Upload
-
- Class upphoto {
- Public $ previewsize = 0.125; // preview the image proportion
- Public $ preview = 0; // whether to generate a preview. The value is 1 and the value is 0.
- Public $ datetime; // random number
- Public $ ph_name; // upload the image file name
- Public $ ph_tmp_name; // temporary image file name
- Public $ ph_path = "../userimg/"; // upload file storage path
- Public $ ph_type; // image type
- Public $ ph_size; // Image size
- Public $ imgsize; // The size of the uploaded image, used to determine the display ratio.
- Public $ al_ph_type = array (image/jpg, image/jpeg, image/png, image/pjpeg, image/gif, image/bmp, image/x-png ); // allows the upload of image types
- Public $ al_ph_size = 1000000; // The file size that can be uploaded
- Function _ construct (){
- $ This-> set_datatime ();
- }
- Function set_datatime (){
- $ This-> datetime = date ("YmdHis ");
- }
- // Obtain the file type
- Function get_ph_type ($ phtype ){
- $ This-> ph_type = $ phtype;
- }
- // Get the file size
- Function get_ph_size ($ phsize ){
- $ This-> ph_size = $ phsize ."
";
- }
- // Get the upload temporary file name
- Function get_ph_tmpname ($ tmp_name ){
- $ This-> ph_tmp_name = $ tmp_name;
- $ This-> imgsize = getimagesize ($ tmp_name );
- }
- // Obtain the original file name
- Function get_ph_name ($ phname ){
- $ This-> ph_name = $ this-> ph_path. $ this-> datetime. strrchr ($ phname, "."); // The last position where the strrchr obtains the object's vertex.
- // $ This-> ph_name = $ this-> datetime. strrchr ($ phname, "."); // Obtain the last position where the point of the file appears.
- Return $ this-> ph_name;
- }
- // Determine the directory for storing uploaded files
- Function check_path (){
- If (! File_exists ($ this-> ph_path )){
- Mkdir ($ this-> ph_path );
- }
- }
- // Determine whether the size of the uploaded file exceeds the permitted size
- Function check_size (){
- If ($ this-> ph_size> $ this-> al_ph_size ){
- $ This-> showerror ("uploading images exceeds 2000KB ");
- }
- }
- // Determine the file type
- Function check_type (){
- If (! In_array ($ this-> ph_type, $ this-> al_ph_type )){
- $ This-> showerror ("incorrect image Upload type ");
- }
- }
- // Upload an image
- Function up_photo (){
- If (! Move_uploaded_file ($ this-> ph_tmp_name, $ this-> ph_name )){
- $ This-> showerror ("file upload error ");
- }
- }
- // Preview the image
- Function showphoto (){
- If ($ this-> preview = 1 ){
- If ($ this-& gt; imgsize [0] & gt; 2000 ){
- $ This-> imgsize [0] = $ this-> imgsize [0] * $ this-> previewsize;
- $ This-> imgsize [1] = $ this-> imgsize [1] * $ this-> previewsize;
- }
- Echo ("ph_name}" width = "{$ this-> imgsize [0]}" height = "{$ this-> imgsize [1]}"> ");
- }
- }
- // Error message
- Function showerror ($ errorstr ){
- Echo"