0

Hello StackOverflow Community,
I want to be able to echo that a file is uploaded in upload/FirstName_LastName_FileName.ext format. In my PHP file, I have this HTML here:

<td>File Stored in:</td>
<td>upload/$uploadName_$filename</td>

but it seems that this code returns upload/$filename. How can I remedy this situation? I'm very new to this so help is greatly appreciated!

EDIT: I was too hasty in trying to get this question answered that I didn't provide enough information. I actually could not use the PHP tags since it was going to be embedded into the message of the mail function. So I found a way by assigning a new variable $uploadPath to the code. The line now looks lke this:

   $uploadPath = "upload/" . $uploadName . "_" . $filename;
   // mail to, subject, message and its table...
   <td>File Stored in:</td>
   <td>$uploadPath</td>

Even still, thank you all for your quick answers! I gave the fastest the checkmark.

3 Answers 3

1

There's a lot of ways to do this. Here's a few:

<td>upload/<?= $uploadName,'_',$filename; ?></td>

<td>upload/<?= $uploadName.'_'.$filename; ?></td>

<td>upload/<?php printf("%s_%s", $uploadName, $filename; ?></td>

<td>upload/<?= $uploadName; ?>_<?= $filename; ?></td>

<td>upload/<?= "{$uploadName}_{$filename}"; ?></td>
Sign up to request clarification or add additional context in comments.

2 Comments

Advise about php.ini and short_tags!, ;D
Yes, if they are using PHP < 5.4 or plan to distribute their code. Otherwise this is fine since in PHP 5.4+ short echo tags are always on. In fact, this is default functionality in all non-deprecated versions of PHP.
0

Use php tags:

<td>File Stored in:</td>
<td>upload/<?php echo $uploadName?>_<?php echo $filename?></td>

Comments

0

try this code:

<td><?php echo 'upload/' . $uploadName . '_' . $filename; ?>**strong text**</td>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.