Jump to content

How to tell user where file was uploaded too?


AJ_V

Recommended Posts

Hi everyone, just wondering - how can you inform the user one where their uploaded file has gone too (including the filename)?

 

Here is my script which uploads to "/images/":

 

<?php
session_start();

$storage = 'images/';

$now= date("Y-m-d_Gis_");

$uploadfile = "$storage/" . basename( $now.$_FILES['Filedata']['name'] );
//$uploadfile = "$storage/" . basename( $_FILES['Filedata']['name'] );

if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( '1 ' . $_FILES['Filedata']['name']);

}else{
echo( '0');
}
?>

 

I have tried inserting the following on the file upload confirmation page but it doesn't seem to show the link:

 

<a href = "<?php echo $_SESSION['name']; ?>">

 

Any ideas? Any help really appreciated!

 

Regards,

James.

Link to comment
Share on other sites

Hi, I have tried the following:

 

<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
}
-->
</style>
</head>

<body>
<div align="center">
<p> </p>
<p> </p>
<p class="style1">File Location:</p>
<?php


echo '<a href="http://rds.vee-media.com/'.$storage."/".$_FILES['Filedata']['name'].'">Your file</a>';
?>

</div>
</body>
</html>

 

But it just links to http://rds.vee-media.com// ?

 

Regards,

James

Link to comment
Share on other sites

Are you being serious...?

Thats obviously going to happen because its on a different page.

If you want to do that on a seperate page you will have to use sessions.

Ill start you off:


<?php
session_start();

$storage = 'images/';

$now= date("Y-m-d_Gis_");

$uploadfile = "$storage/" . basename( $now.$_FILES['Filedata']['name'] );
//$uploadfile = "$storage/" . basename( $_FILES['Filedata']['name'] );

if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( '1 ' . $_FILES['Filedata']['name']);
$_SESSION['filename'] = $storage."/".$_FILES['Filedata']['name'];

}else{
echo( '0');
}
?>

Im pretty sure:

$uploadfile = "$storage/" . basename( $now.$_FILES['Filedata']['name'] );

should be this though:

$uploadfile = "$storage" . basename( $now.$_FILES['Filedata']['name'] );

 

otherpage:

<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
}
-->
</style>
</head>

<body>
<div align="center">
<p> </p>
<p> </p>
<p class="style1">File Location:</p>
<?php


echo '<a href="http://rds.vee-media.com/'.$_SESSION['filename'].'">Your file</a>';
?>

</div>
</body>
</html>

 

May be some minor errors since I didnt it quickly.

Link to comment
Share on other sites

That seemed to  work, yes! But it is looking for the original filename (when you link to it), but in the PHP, it adds the date to  the begining of the file so the confirmation link would link too:

 

http://rds.vee-media.com/images/Freestyle.jpg

 

But the real file would be

 

http://rds.vee-media.com/images/2007-03-11_135905_Freestyle.jpg

 

Any idea???

 

Regards,

James.

 

P.S Thanks for your help!

Link to comment
Share on other sites

you should do this then:

<?php
session_start();

$storage = 'images/';

$now= date("Y-m-d_Gis_");

$newname = $now.$_FILES['Filedata']['name'];

$uploadfile = "$storage/" . $newname;
//$uploadfile = "$storage/" . basename( $_FILES['Filedata']['name'] );

if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( '1 ' . $_FILES['Filedata']['name']);
$_SESSION['filename'] = $storage."/".$newname;

}else{
echo( '0');
}
?>

Link to comment
Share on other sites

You need: (for size and type):

<?php
session_start();

$storage = 'images/';

$now= date("Y-m-d_Gis_");

$newname = $now.$_FILES['Filedata']['name'];

$uploadfile = "$storage/" . $newname;
//$uploadfile = "$storage/" . basename( $_FILES['Filedata']['name'] );

if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( '1 ' . $_FILES['Filedata']['name']);

$_SESSION['filename'] = $storage."/".$newname;
$_SESSION['type'] = $_FILES['Filedata']['type'];
$_SESSION['size'] = $_FILES['Filedata']['size'];

}else{
echo( '0');
}
?>

 

and:


<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
font-family: Geneva, Arial, Helvetica, sans-serif;
font-weight: bold;
}
-->
</style>
</head>

<body>
<div align="center">
<p> </p>
<p> </p>
<p class="style1">File Location:</p>
<?php


echo '<a href="http://rds.vee-media.com/'.$_SESSION['filename'].'">Your file</a><br>';
echo "Size: " . $_SESSION['size'] . "<br>";
echo "Type: " . $_SESSION['type'] . "<br>";
?>

</div>
</body>
</html>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.