hi,
i am new to php. i want to get the uploaded filename,uploadedby,date, and size of the file. dont know how to get the name of the file and size. so please any one....

<html>
<body>
<form enctype="multipart/form-data" action="upload2.php" method="POST">
<table>
<tr>
<td><img src="Logofinalcopy.gif"></td>
</tr>
</table>
<table>
<br><br>
<tr>
	<td>
		<strong>Please choose a file: </strong>
	</td> 
	<td>
		<input name="uploaded" type="file"><br>
    </td>
</tr>
<tr><td>
<input type="submit" value="upload"></td></tr>

</table></form></body></html>
<?php
ob_start();
@session_start();
require_once ("check.php");
$con=mysql_connect("10.70.1.50","invensis","invensis");
if(!$con)
    {
             die('Could not connect: ' . mysql_error());
    }
mysql_select_db("database_myproject",$con);


?>
<html>
<body>
<table border="1" cellspacing="0" cellpadding="0" align="center" style="width: 500px">
<tr>
<th>filename</th>
<th>uploadedby</th>
<th>uploadeddate</th>
<th>size</th></tr>


<tr>
<td><?php ?></td>
<td><?php echo $username; ?></td>
<td><?php echo date("Y-m-d");?></td>
<td><?php ?> </td></tr>
<?php
  
?>
</table></body></html>

Hi,
In upload2.php file using the following line.
print_r($_FILES);

you can see the name of the file,size,type etc.

Thank you,
Prem

actually i need to display the filename , uploadedby,uploaded date, and size of the file which is uploaded in a table. so please check this once again..

hi,
check whether what output your are getting.In your code you does not mentioned in which location your file is uploaded.

<td><?php print_r($_FILES); ?></td>
<td><?php echo $username; ?></td>
<td><?php echo date("Y-m-d");?></td>
<td><?php ?> </td></tr>


Thank you,

actually i need to display the filename , uploadedby,uploaded date, and size of the file which is uploaded in a table. so please check this once again..

iam getting Array() in the filename column.
ok i am sending upload2.php code also...

<?php
 $dirname=$_POST['projectname'];
 $dir="files";

    if(is_dir($dirname))
    {
        $target = "$dir/$dirname/";
        $target = $target . basename( $_FILES['uploaded']['name']) ; 
        $ok=1; 
        if ($ok==0) 
        { 
            Echo "Sorry your file was not uploaded"; 
        } 
        else 
        { 
            if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
            { 
                echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
                echo '<a href="login_success.php">Back</a>';
            } 
            else 
            { 
                echo " "; 
            } 
        }
     }
     else
     {
        $path="$dir//$dirname";
        @mkdir($path,0777,true);
        $target = "$dir/$dirname/";
        $target = $target . basename( $_FILES['uploaded']['name']); 
        $ok=1; 
        if ($ok==0) 
        { 
            echo "Sorry your file was not uploaded"; 
        } 
        else 
        { 
            if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
            { 
                echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
                
            } 
            else 
            { 
                echo " "; 
            } 
        }
     }
    
 
?>

Is your file is uploaded in the following destination.

Is your file is uploaded in the following destination.

yes. i can see the uploaded files in files folder. should we need to create sessions for this...

In upload2.php when you use the below line you can see the file name.


echo "File name " . $_FILES["file"]["name"] . "<br />";


If you want to display the file name in table. you must assign the file name in variable and pass it into the url.

In upload2.php when you use the below line you can see the file name.


echo "File name " . $_FILES["file"]["name"] . "<br />";


If you want to display the file name in table. you must assign the file name in variable and pass it into the url.

can u give me clear explanation, how to display filename in table.

you must use java script to pass the values using the hidden attribute.That is the simplest way.

You can try this code but it is not efficient one.
Remove the follwing line in your code.
echo '<a href="login_success.php">Back</a>';
Use this:
$filename=$_FILES;
header("Location:login_success.php?i=$filename);


In display file use the code:
<?php $filename=$_REQUEST?>
<td><?php $filename ?></td>
<td><?php echo $username; ?></td>
<td><?php echo date("Y-m-d");?></td>

change the following line.
<a href="login_success.php">Back</a>

Try this may be it will also help you.
$filename=$_FILES;
<a href="login_success.php?i=$filename">Back</a>

change the following line.
<a href="login_success.php">Back</a>

Try this may be it will also help you.
$filename=$_FILES;
<a href="login_success.php?i=$filename">Back</a>

no i am not getting any filename. ok i removed completly this line
<a href="login_success.php">Back</a>. assume that it is not their.

You can also try this code.
$filename=$_FILES;
<a href="login_success.php?i=$filename">Back</a>';

Check whether the file name you get.
echo $filename=$_FILES;

check whether you are getting the file name;
$filename=$_FILES;
echo $filename;

check whether you are getting the file name;
$filename=$_FILES;
echo $filename;

It is not printing filename. iam in a confusion wer to keep that.

Inside the if block;

if(move_uploaded_file($_FILES, $target))
{
echo "The file ". basename( $_FILES). " has been uploaded";
$filename=$_FILES;
echo $filename;
print_r($_FILES);
echo '<a href="login_success.php">Back</a>';

}

Inside the if block;

if(move_uploaded_file($_FILES, $target))
{
echo "The file ". basename( $_FILES). " has been uploaded";
$filename=$_FILES;
echo $filename;
print_r($_FILES);
echo '<a href="login_success.php">Back</a>';

}

i am getting the following on the browser
The file has been uploadedArray ( [uploaded] => Array ( [name] => view.php [type] => text/plain [tmp_name] => C:\WINDOWS\temp\php72.tmp [error] => 0 => 1654 ) )

Sorry i mistakenly typed uploadedfile..change this line.

$filename=$_FILES;
echo $filename;

Sorry i mistakenly typed uploadedfile..change this line.

$filename=$_FILES;
echo $filename;

The file has been uploadedArray ( [uploaded] => Array ( [name] => view.php [type] => text/html [tmp_name] => C:\Documents and Settings\Administrator\Local Settings\temp\php86.tmp [error] => 0 => 1654 ) )

you must get the filename;Then only you can able to pass it to another page.


$filename=$_FILES;
echo "********".$filename;

try and check once again...

you must get the filename;Then only you can able to pass it to another page.


$filename=$_FILES;
echo "********".$filename;

try and check once again...

yes i am getting the uploaded filename as empdetails and also size.
The file has been uploaded********empdetails.phpArray ( [uploaded] => Array ( [name] => empdetails.php [type] => text/plain [tmp_name] => C:\WINDOWS\temp\php8F.tmp [error] => 0 => 5048 ) )

try this line..
<a href="login_success.php?i=$filename">Back</a>

try this line..
<a href="login_success.php?i=$filename">Back</a>

actually this line is not there. i mistakenly type it.
<a href="login_success.php?i=$filename">Back</a>

try this line..
<a href="login_success.php?i=$filename">Back</a>

wat the thing is i need to place that filename and size in the table. so please help me for that...

put the line

<a href="login_success.php?i=$filename">Back</a>

In table display use the code:

<?php $filename=$_REQUEST[i]?>
<td><?php $filename ?></td>
<td><?php echo $username; ?></td>
<td><?php echo date("Y-m-d");?></td>

put the line
<a href="login_success.php?i=$filename">Back</a>

In table display use the code:
<?php $filename=$_REQUEST?>
<td><?php $filename ?></td>
<td><?php echo $username; ?></td>
<td><?php echo date("Y-m-d");?></td>

this line is not present. i am sorry for that.
<a href="login_success.php?i=$filename">Back</a>
i had kept this line
<?php $filename=$_REQUEST?>
but i didnt get it.

Remove the follwing line in your code. header("Location:login_success.php?i=$filename); put the line <a href="login_success.php?i=$filename">Back</a> when you click the back.It will go to login_success.php

In table design you include the code mentioned below

<?php print_r($_REQUEST); ?>
<?php $filename=$_REQUEST[i]?>
<td><?php echo $filename ?></td>
<td><?php echo $username; ?></td>
<td><?php echo date("Y-m-d");?></td>

Remove the follwing line in your code.
header("Location:login_success.php?i=$filename);

put the line
<a href="login_success.php?i=$filename">Back</a>


when you click the back.It will go to login_success.php

In table design you include the code mentioned below
<?php print_r($_REQUEST); ?>
<?php $filename=$_REQUEST?>
<td><?php echo $filename ?></td>
<td><?php echo $username; ?></td>
<td><?php echo date("Y-m-d");?></td>

but i am not having any login_success.php page. i mistakenly typed it.

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
echo '<a href="login_success.php">Back</a>';
}

In the above code you have mentioned it.Then when u click the back button where it will go..In which page you want to display the table.
You want to display the table in same upload2.php file?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.