Jump to content

[SOLVED] Deleting Files via HTML form - Error


winmastergames

Recommended Posts

I am trying to learn the $_GET Function and I looked online to learn it and now i kind of see how it works but when i tried to make a script that deletes a file that is typed into a form it comes up with a error can you please find out whats wrong so i know for next time i try to use the $_GET function

Here is my scripts

 

index.html

<form action="delete-the-file.php" method="get">
File to delete: <input type="text" name="filename" />
<input type="submit" />
</form>

 

delete-the-file.php

<?php
   if (unlink($_GET["filename"])) {
      print "Deleted $_GET["filename"]!\n";
   } else {
      print "Delete of $_GET["filename"] failed!\n";
   }
?>

 

But it comes up with this error??

Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\filedeleteform\delete-the-file.php on line 3

You'll probably only want files within a certain directory to be able to be removed. eg;

 

<?php
   if (unlink('public/' . $_GET["filename"])) {
      print "Deleted {$_GET['filename']}!\n";
   } else {
      print "Delete of {$_GET['filename']} failed!\n";
   }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.