I am writing a php code to allow the user to submit an image and upload it to the server. I am working on this and the server receives the image, but it seems that the server is also accepting .avi and .flv files. Whether I am a file or not an image, but why does it not work, to check if I write / else statement. Thanks
This is my php code
$ tmpPath = $ _FILES ["image"] ["tmp_name"]; $ Transferred path = "deposit- img /" $ _POST ["class"] "/" $ _FILES ["image"] ["name"]; $ FullURL = parse_url ($ _ server ['HTTP_REFERER']); $ Query = Explosion ("& amp;", $ full URL ["query"]); // just select the first query $ prevPage = "gallery.php" "?" . $ Query [0]; // I get the file type here $ fileType = strpos ($ _ files ["image"] ["type"], "picture /"); // If there is no image then it redirects to the previous page and sends the message ($ fileType === incorrect || ($ _FILES ["image"] ["size"]) == 0 || $ $ _FILES [ "Image"] ["size"] / 1024> 5000) {$ prevPage = $ prevpage "& amp; imgSubmit = any # imgSubmitForm"; Header ("Location:". $ PrevPage); } {Move_uploaded_file ($ tmppath, $ movedPath); Else if ($ _FILES ["image"] ["size"]> gt; 0) {// if file is an image, then (! Is_file ($ transfered penetration)) } And {while (is_file ($ moved path)) {$ extension = strrchr ($ transfered penetration, "."); $ Transfered penetration = straw_release ($ extension, "", $ transfered penetration) "1" $ extension; } Move_uploaded_file ($ tmpPath, $ transfered penetration); } $ PrevPage = $ prevPage "& amp; imgSubmit = Submission # imgSubmitForm"; Header ("Location:". $ PrevPage); }
} and if ($ _FILES ) ["Image"] ["size"]> gt; // If the file is an image The comment on this line is fundamentally misleading. The size key in the $ _ FILES file is in bytes; There is nothing to do with it that "file is an image" (Specifically, it is the physical size of the not image). If you need to know that If a file is an image, then your best bet is to use the function. This function will return the size of an image if it is an image type that recognizes PHP, or zero if that one image does not appear. Do not use
type to determine whether a file is an image or not, the area of $ _ FILES This field is populated by the browser It is not by the server, and it can contain misleading and / or flat-out wrong information.
Comments
Post a Comment