Jump to content

Recommended Posts

Dear all:

 

I want to read an uploaded filename, say "mypic.jpg" to create a link to this image without having to ask the users to enter the filename "mypic.jpg" when uploading it.  My upload code works file but it's not on the same page.  I'm working on my "index.php" page and included the upload.php page "<?php include("upload.php"); ?>" in it.  Here's the sample of my code in the upload.php page (the code for the form is separate and not included here):

 

<?php

if (array_key_exists('submit', $_POST)) {  //  (array_key_exists('upload', $_POST))

  // define constant for upload folder

  define('UPLOAD_DIR', '/var/www/itrdweb/advancednetworkingplan/comments/');

  // replace any spaces in original filename with underscores and assign to a simpler variable (optional but important)

  $file1 = str_replace(' ', '_', $_FILES['upload1']['name']);

  // move the file to the upload folder and rename it

  $file1_renamed = time().$file1;

  move_uploaded_file($_FILES['upload1']['tmp_name'], UPLOAD_DIR.$file1_renamed);

}

?>

 

I want to use the variable "$file1_renamed" in my index.php page to create a link to this file like this:

 

<table>

  <tr>

    <td<a href="/comments/"<?php echo($file1_renamed); ?>>Draft</a></td>

  </tr>

</table>

 

I have tried many different ways and it seemed that this variable "$file1_renamed" does not carry any value (although it does contain the filename for upload).  Any ideas and suggestions ?  Many thanks!

$dir = "path/to/your/files";
$dh = opendir($dir) or die ("could not open dir");
while ( !(($file = readdir($dh)) === false) )
{

if (($file != ".") && ($file != ".."))
{
//echo your link here using $file for name of the file
//this will list all the images in the folder
}
}

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.