Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 5th, 2006, 8:01 AM   #1
tumbleTetris
Programmer
 
Join Date: May 2006
Posts: 39
Rep Power: 0 tumbleTetris is on a distinguished road
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).
tumbleTetris is offline   Reply With Quote
Old Jun 5th, 2006, 9:34 AM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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?
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jun 5th, 2006, 9:40 AM   #3
tumbleTetris
Programmer
 
Join Date: May 2006
Posts: 39
Rep Power: 0 tumbleTetris is on a distinguished road
oh, yes I know that.

I'm doing this as sort of practice, its not supposed to have any practical purposes
tumbleTetris is offline   Reply With Quote
Old Jun 5th, 2006, 10:32 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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'];
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jun 5th, 2006, 11:33 AM   #5
tumbleTetris
Programmer
 
Join Date: May 2006
Posts: 39
Rep Power: 0 tumbleTetris is on a distinguished road
thanks, that done the trick
tumbleTetris is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:12 PM.

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