I noticed you guys have the function so I thought I would ask. I am also using dropzone on my site but I cannot for the life of me figure out how to check for an already uploaded image and display "file exists" if found. I have found code that lets me know the file is already in the dropzone box but not if the image is on the server. Please help.
Dropzone question
13362 13364 Currently it's using a pretty simple method. Basically you just need to check if a generated hash exists in a database, and if it does, throw back an error.
We'll be moving to a more complicated system soon. One that uses IQDB as the backend for that database. With that our dupe detection should be much, much more accurate.
13365 Dropzone doesn't do that. You have to upload the file to the server, have some code there check for existing files (e.g. compare hashes in a database) then respond accordingly.
13366 Sounds good. I already add the files in a database, and know how to check if it's there, but I'm not sure how to implement it so it stops the upload.
Here's the code I have (it came with the plugin, not my code)
function dropzonejs_upload() {
if ( !empty( $_FILES ) && wp_verify_nonce( $_REQUEST['my_nonce_field'], 'protect_content' ) ) { $uploaded_bits = wp_upload_bits( $_FILES['file']['name'], null, //deprecated file_get_contents( $_FILES['file']['tmp_name'] ) ); if ( false !== $uploaded_bits['error'] ) { $error = $uploaded_bits['error']; return add_action( 'admin_notices', function() use ( $error ) { $msg[] = '<div class="error"><p>'; $msg[] = '<strong>DropzoneJS & WordPress</strong>: '; $msg[] = sprintf( __( 'wp_upload_bits failed, error: "<strong>%s</strong>' ), $error ); $msg[] = '</p></div>'; echo implode( PHP_EOL, $msg ); }); } $uploaded_file = $uploaded_bits['file']; $uploaded_url = $uploaded_bits['url']; $uploaded_filetype = wp_check_filetype( basename( $uploaded_bits['file'] ), null ); $upload_basedir = WP_CONTENT_DIR . '/uploads'; if ( file_exists("$upload_basedir/$uploaded_file")) { } } die();
}
I was gonna try and run that before the upload starts but no luck.
All images remain property of their original owners. Site & code © wallhaven.cc 2024. Privacy Policy · Terms of Service