Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   using input names to find and display files. (http://www.programmingforums.org/showthread.php?t=10186)

tumbleTetris Jun 5th, 2006 8:01 AM

using input names to find and display files.
 
:

<?php
/* if the "submit" variable does not exist, the form has not been submitted - display initial page */
if (!isset($_POST['submit'])) {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  <input name="File" size="15">
  <input type="submit" name="submit" value="Go">
</form>

<?php
}
else {
// open file
$fh = fopen($File, 'r') or die('Could not open file!');
// read file contents
$data = fread($fh, filesize($File)) or die('Could not read from file!');
// close file
fclose($fh);

// get detail
// print file contents
echo "<img src=\"$File\">";

}
?>


the concept is simple: gets an input in the form then outputs the corresponding picture of the same name.

Doesn't work, I have no idea why, plus the fact that I'm having difficulty testing it.. (slow net connection = 30++ second waits between testing).

Infinite Recursion Jun 5th, 2006 9:34 AM

Wouldn't this imply that the user would have to know the filename ahead of time? Why not just list an image directory with hyperlinks?

tumbleTetris Jun 5th, 2006 9:40 AM

oh, yes I know that.

I'm doing this as sort of practice, its not supposed to have any practical purposes ;)

Infinite Recursion Jun 5th, 2006 10:32 AM

Oh, in that case... You are trying to open a file referenced in code as $File that is never defined. Try this, right above where you are trying to open the file...

$File = $_POST['File'];

tumbleTetris Jun 5th, 2006 11:33 AM

thanks, that done the trick :)


All times are GMT -5. The time now is 8:00 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC