How to deny identical images being uploaded with PHP -
I want to search for a directory by Imagetype or similar variable .. before the image is uploaded to that essay < / P>
My goal is to find Blob of images in that directory with php, and if any result is matched (meaning that there will be duplicate uploads of the same image) of "pre-uploaded file" Will come back together.
This is related to image files ...
Here is the code that I think I can add ..
/ / Element (values) $ $ _FILES ['ImageFile'] Array // Let's update your index status by using these values $ image name = str_replace ('', '-', strtolower ($ _ files ['ImageFile'] [ 'Name']); $ image size = $ _FILES ['ImageFile'] ['size']; // Get the original image size $ TempSrc = $ _FILES ['ImageFile'] ['tmp_name']; // tmp file The name is stored in the PHP tmp folder $ ImageType = $ _FILES ['ImageFile'] ['Type']; // Get the type, "Image / PNG", Return Image / JPEG, Text / Plain etc. Let's use $ Image Variable to check the uploading file. // We can check the valid image format PHP uses swiss details, the PHP switches are similar to the IF / ELSE statement / if we want to compare a variable with several different value switches (stroller ($ imagetip)) {case 'image / PNG': $ build Image = imagecreatefrompng ($ _ Hailen [ 'Image File'] [ 'tmp_name']); break; Case 'Image / GIF': $ build image = imagecreatefromgif ($ _ files ['ImageFile'] ['tmp_name']); break; Case 'Image / JPEG': Case 'Image / PJPEG': $ build image = imagecreatefromjpeg ($ _ files ['imagefile'] ['' tmp_name ']); break; Default: Dead ('unsupported file, please check the file and try again!'); // Output error and exit}
In addition to other things, these are considered Such systems:
- The user can upload the same file name, but with different materials (warning, update, replace, duplicate?)
- Can upload content, but under a different name (warning, update, replace, duplicate?)
A few years ago, in a file I had to design, only the uploaded files were changed to the same user. User can upload the exact same file name or content (to avoid duplicate data, it was to be linked to the existing file name), but If the content was different, then the file would be twice as exact with the same name (two different users).
The DB table looks like this:
Make table user's files (id INT is not unknown, primary primary key, user_id INT is not solved, ...) Field file name VARCHAR (256) No, Null - Original file name file_sha VA RCHARR (40) Noall, - Content SHA1 file_md5 is VARCHAR (16) - Content MD5 file_Link is VARCHAR (1024) - Unicode 1 (basic filename)) * ... --- other fields) [*] file_lnk field targets on the server In which there is a calculation path on the basis of some uplift. Actually, I used and on the uploaded file (right now in upload upload) and Viewed in the database for the uploaded file; SHA1 or current user ID and file name (i.e.: SELECT ... WHERE file_sha = & lt; computed_sha1 & gt; OR (user_id = & lt; current_UID & gt; and file name = & lt; uploaded_filename ) To check the best match results with an algorithm, as a result of the database to check any match you were asked: - If SHA1 is something Also matches the content, probably had already been uploaded, even if the MD5 field was also compiled In comparison.
- If the file belongs to the same user (same
user_id ), then filename is required only when necessary - In case , The file content was to be linked and the existing content (the same
file_lnk ) was created in a new line in the database - If the
User_id and file name were the same, the same file was uploaded - If the same file content was attached to another user, then a new The row was created, creating a new
file_lnk and updating the file_sha and file_md5 . - In any other case, this new material (by simply changing the actual
file_lnk file) - any other matter In, a new file and DB table row were created
Comments
Post a Comment