PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Wed Nov 26, 2014 4:23 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Apr 08, 2012 10:53 pm 
Offline
Forum Newbie

Joined: Wed Apr 04, 2012 8:54 pm
Posts: 22
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.

Syntax: [ Download ] [ Hide ]
print('<table>');
print('<tr><td width=100px>File Name</td><td>File Size</td></tr>');
print('<tr><td>'. $_FILES['uploadedfile']['name'] . '</td><td>'. round($_FILES['uploadedfile']['size']/1024,4) . ' Kb</td></tr>');
print('</table>');


I have tried to insert the upload.php code in a new html
Syntax: [ Download ] [ Hide ]
 <form name="upload" method="POST">
            <input type=hidden name=MAX_FILE_SIZE value=500000>
            <input type=file name=uploadedfile>
            <input type=submit name="upload" value=Upload>
        </form>


and insert the upload.php code right below head
Syntax: [ Download ] [ Hide ]
<?php
if(!empty($_POST['upload']))
{
//All the code for upload file including the table containing uploadedfile name and size
}
?>

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


Top
 Profile  
 
PostPosted: Mon Apr 09, 2012 7:34 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2775
Location: .za
adhi91 wrote:
What is missing? or are there any better way to do this?

If you want to display the information on the same page that displays your submission form you have to call the page on itself;
Syntax: [ Download ] [ Hide ]
 // you can do this, leave the action attributes' value blank
 <form action="" method="post" enctype="multipart/form-data" >
// or use $_SERVER['PHP_SELF']
 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" >
 

You would also have to test if the button has been submitted
Syntax: [ Download ] [ Hide ]
<?php
 if (isset($_POST['upload']) && $_POST['upload'] == 'Upload')) {
 // button has been clicked, continue to process form.
 }
 

Depending on where you want the information to be displayed, above or below the form, you can move the snippet of code above to the appropriate position.

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
PostPosted: Mon Apr 09, 2012 8:27 pm 
Offline
Forum Newbie

Joined: Wed Apr 04, 2012 8:54 pm
Posts: 22
Thanks. I use the first one, it works.

if I add another download button, where I only wanted to download the uploaded file.
I try in the sequence
Syntax: [ Download ] [ Hide ]
echo"<input type=file name=uploadedfile onchange=this.form.submit()>";
//the process for upload
echo"<form action='' method=POST><input type=submit value=Download name=download></form>";
//the process for download
 

It works if I use it separately.
I also attempt to insert the download process in the upload process using if statement
Syntax: [ Download ] [ Hide ]
//if upload successful
//download process is next using isset to check if download is click
 

However, this method not working.

How can I tell user that download only works if I already upload the file?


Top
 Profile  
 
PostPosted: Tue Apr 10, 2012 12:07 am 
Offline
DevNet Master
User avatar

Joined: Sun Feb 15, 2009 12:08 pm
Posts: 2775
Location: .za
adhi91 wrote:
How can I tell user that download only works if I already upload the file?

You could use javascript to enable the button once the upload has been completed; or in your if statement to check if a file has been uploaded, you could print the button to the browser.

_________________
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group