List Uploaded file in one web page as the submit button

Hi,

I have two files which is index.php and upload.php
In index I have a browse button and a submit button. If I click the submit button, it will direct to a new web page and show the uploaded file name and size.
All of this works.
Now I want to show the uploaded file name and size on the same web page as the browse and submit button.

[php]
print(’

’);
print(‘’);
print(’’);
print(’
File Name File Size
’. $_FILES[‘uploadedfile’][‘name’] . ‘ ’. round($_FILES[‘uploadedfile’][‘size’]/1024,4) . ’ Kb
’);[/php]

I have tried to insert the upload.php code in a new html
[php]



[/php]

and insert the upload.php code right below head
[php]

<?php if(!empty($_POST['upload'])) { //All the code for upload file including the table containing uploadedfile name and size } ?>[/php]

What is missing? or are there any better way to do this?

Well, first, you must understand that PHP is SERVER-SIDE code. Therefore, no PHP code ever get’s into a browser. Just the things printed/echo’d from the code. So, you could post to yourself, but, there would not be any PHP code there to upload the file. Therefore, you would either have to use Javascript/Jquery or post to the same file. Therefore, you will need to add an action in the form tag. Something like:

This way, it will pull the same page, but, using whatever new file you selected. Since the page is calling a server page, the PHP will execute and send the results back to the browser.

Of course, now that I have stated all that… You can load any PHP file or code into a iFrame. When that happens, the PHP file is executed and it’s output is placed into the iFrame which then shows up on the screen. But, the problem there is that you still need a button and JS routine to load the iFrame…

Hope all that helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service