AJ_V Posted March 11, 2007 Share Posted March 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted March 11, 2007 Share Posted March 11, 2007 <?php echo "You're file is location: {$uploadfile}"; ?> Wouldn't it? Quote Link to comment Share on other sites More sharing options...
papaface Posted March 11, 2007 Share Posted March 11, 2007 <?php echo '<a href="http://www.yourdomain.com/'.$storage."/".$_FILES['Filedata']['name'].'">Your file</a>'; ?> Quote Link to comment Share on other sites More sharing options...
AJ_V Posted March 11, 2007 Author Share Posted March 11, 2007 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 Quote Link to comment Share on other sites More sharing options...
papaface Posted March 11, 2007 Share Posted March 11, 2007 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. Quote Link to comment Share on other sites More sharing options...
AJ_V Posted March 11, 2007 Author Share Posted March 11, 2007 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! Quote Link to comment Share on other sites More sharing options...
papaface Posted March 11, 2007 Share Posted March 11, 2007 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'); } ?> Quote Link to comment Share on other sites More sharing options...
AJ_V Posted March 11, 2007 Author Share Posted March 11, 2007 That is fantastic! Thanks very very much! Quote Link to comment Share on other sites More sharing options...
AJ_V Posted March 11, 2007 Author Share Posted March 11, 2007 One last thing, is there anyway to display details of the file with the link? E.g. file size, file type etc? Regards, AJ Quote Link to comment Share on other sites More sharing options...
papaface Posted March 11, 2007 Share Posted March 11, 2007 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> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.