Jump to content

jhb

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Everything posted by jhb

  1. Got this to work: $page = $_GET['page']; if (isset($_GET['page']) && $_GET['page'] == $page) { if (file_exists("pages/$page.php")) { include("pages/$page.php"); } else { echo "<h1>Finner ikke siden</h1>"; } } else { include("pages/index.php"); }
  2. yeah. just figured it out But. I dont have a clue to how to show an error page if the desired file that are to be included don't exists.
  3. I have a menu-item that links to for example example.com?page=y Then I need my php code to pull that "y" and put it in "include("pages/'$thatpage'.php");" Got this, that doesn't work: if (isset($_GET['page']) && $_GET['page'] == $page) { include("pages/'$page'.php"); } else { include("pages/index.php"); } ^ $page should then become the desired page, for example "y" This does though: if (isset($_GET['page']) && $_GET['page'] == y) { include("pages/y.php"); } else { include("pages/index.php"); } But i need it to be flexible, so i don't have to update my file every time i add a new page.
  4. Thanks. I was thinking about making it like the delete-function, so I guess it would be pretty easy after a couple hours of trying different stuff...
  5. would there be a way of implementing a way to change the name of file in that code, without showing the file extension? I dont know much of the rename() function so...
  6. nice. nice. I just added an javascript alert-box as an temporarily solution, where the OK-button redirects back to the index-file, but i think i will use your code instead
  7. I got one problem though; when i delete a file I would want a list of the remaining files below the message "example_file.txt was removed." I have tried this, but it doesn't work: <?php $dir = "files/norsk/"; if (!$handle = opendir($dir)) { echo "Kunne ikke åpne mappen ".$dir; exit; } while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(isset($_GET['rm'])) { if($_GET['rm'] == $file) { if(unlink($dir.$file)) { // File removed $no1 .= $dir.$file.' was removed.'; $extension = end(explode('.', $file)); $filename_no_ext = substr($file, 0, -(strlen($extension) + 1)); $no .= '<img src="document-icon.png" /> '.$filename_no_ext.' <a href="/files/norsk/'.$file.'"><img src="down-icon.png" /></a> <i><a href="?rm='.$file.'" style="color:grey;"><img src="delete-icon.png" /></a></i><br />'; } else { // Failed to remove file $no1 .= $dir.$file.' could not be removed. Check your paths and permissions.'; $extension = end(explode('.', $file)); $filename_no_ext = substr($file, 0, -(strlen($extension) + 1)); $no .= '<img src="document-icon.png" /> '.$filename_no_ext.' <a href="/files/norsk/'.$file.'"><img src="down-icon.png" /></a> <i><a href="?rm='.$file.'" style="color:grey;"><img src="delete-icon.png" /></a></i><br />'; } } } else { $extension = end(explode('.', $file)); $filename_no_ext = substr($file, 0, -(strlen($extension) + 1)); $no .= '<img src="document-icon.png" /> '.$filename_no_ext.' <a href="/files/norsk/'.$file.'"><img src="down-icon.png" /></a> <i><a href="?rm='.$file.'" style="color:grey;"><img src="delete-icon.png" /></a></i><br />'; } } } closedir($handle); ?> <p style="color:grey;vertical-align:middle;"><?=$no1?></p> <p style="color:black;vertical-align:middle;"><?=$no?></p>
  8. Thanks Pawn! Worked great! Only thing that is bad is tha i dont learn a thing by copy-paste
  9. It would also be great if you could help me with not showing the file extension of each file
  10. I have a download-list, and want to have a delete-button/link at each file. I have tried different codes, but i'm new to php and need some help. if ($handle = opendir('files/engelsk/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $en .= '» <a href="/files/engelsk/'.$file.'">'.$file.'</a> - <i><a href="#">Delete file</a></i><br />'; } } closedir($handle); } It's the "<a href="#">Delete file</a>" I want to be the delete-button. Please help!
×
×
  • 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.