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

Link to comment
Share on other sites

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";
   }
?>

Link to comment
Share on other sites

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.