Page 1 of 1

How to show the uploaded filenames to the user?

Posted: Thu Mar 06, 2014 11:51 pm
by yandao
Hi,

How to show the uploaded file name to the user?

After the users have uploaded the file, is there a way to show the file that they have uploaded under the profile?

Currently it is just upload, but I am thinking of showing the file name that they have uploaded earlier on the profile.

Code: Select all

if ( isset($_FILES['tb-documents']) ) {								
						$documents = $_FILES['tb-documents'];
						foreach ( $documents['name'] as $key => $value ) {
							if ( $documents['name'][$key]) {
								$document = array(
									'name' => $documents['name'][$key],
									'type' => $documents['type'][$key],
									'tmp_name' => $documents['tmp_name'][$key],
									'error' => $documents['error'][$key],
									'size' => $documents['size'][$key]							
									);

								$status = wp_handle_upload($document, array('test_form' => false));
								
								if( !isset($status['error']) ) {
									$uploads = wp_upload_dir();
									add_user_meta($user->ID, 'tb-documents', $uploads['url'].'/'.basename($status['file']));
								}																	
							}
							
						}
					}
and the code that I am pulling data from is this.

Code: Select all

if ( !empty($documents) ) {
				for ( $y = 0; $y < count($documents); $y++ ) {
					$content .= '<br><a href="' . $documents[$y] . '#">Download Document #' . ($y+1) . '</a> (<a href="?page=tb-tutors&id=' . $user->ID . '&delete=' . esc_attr(basename($documents[$y])) . '">Delete</a>)';
				}
			}
The upload is working well on the user profile. However, I want to pull out the file name that they have uploaded and display only the uploaded file name to them. I want to change the static "Download Document #" to the actual filenames. Is there a way to change that? I don't really need the link for the users to download but rather to show only the filenames.

Which variable should I use?

Please advice.

Re: How to show the uploaded filenames to the user?

Posted: Sun Mar 09, 2014 12:15 pm
by Christopher
Maybe save the file names in a data table with the associated User ID. Or put the User ID in the file name and use glob() to fiind them.