Excellent
-
Thanks! I spent a day wondering why the temporary file was not longer there then another day finding out that CF7 is moving that file. So this is exactly what I was trying to figure out. It does look like files could be overwritten if they are uploaded with an existing name. You can probably do something like the following to ensure files get unique names and are not overwritten.
// Get the path to the upload directory. $wp_upload_dir = wp_upload_dir(); $upload_path = $wp_upload_dir['path']; $unique_filename = wp_unique_filename($upload_path, basename($filename)); $attachFileName = $upload_path . '/' . $unique_filename; copy($filename, $attachFileName); // Prepare an array of post data for the attachment. $attachment = array( 'guid' => $attachFileName, 'post_mime_type' => $filetype['type'], 'post_title' => preg_replace('/\.[^.]+$/', '', $unique_filename), 'post_content' => '', 'post_status' => 'inherit' );
- The topic ‘Excellent’ is closed to new replies.