Solved

PHP - How to use a textbox and a button to remove a certain file?

Posted on 2011-09-09
6
204 Views
Last Modified: 2012-05-12
Hello everyone! The title may not be that clear what I'm trying to do. First of all, I have created multiple paths like this:

F:\MyFolder\1\testfile.txt
F:\MyFolder\2\testfile.txt
F:\MyFolder\3\testfile.txt

You notice that the only thing that changes in the path is the middle. Now my question. Can I use a textbox to determine the numbers 1, 2, 3 so If I for example type a 2 in the textbox and then click a button, the file
F:\MyFolder\2\testfile.txt will be removed. And if I type a 3 the file F:\MyFolder\3\testfile.txt will be removed.
Basically everything in the path stays the same only the second folder changes.

Thank you for your support,

einstein10
0
Comment
Question by:einstein10
  • 3
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
OmniUnlimited earned 500 total points
Comment Utility
Sure.  You could set up PHP like this:

<?php

if (isset($_POST)) {
    $fileroot = "F:\MyFolder\";
    $filename = "\testfile.txt";
    $filepath = $fileroot . $_POST['fileindex'] . $filename;
    unlink($filepath);
}
echo '<form method="post" action="">';
echo '<label for "fileindex">Index of file to be deleted: <input type="text" name="fileindex" id="fileindex" value="' . $_POST['fileindex'] . '" />';
echo '<input type="submit" name="submit" value="Submit" />';
echo '</form>';
?>

Open in new window

0
 
LVL 17

Expert Comment

by:OmniUnlimited
Comment Utility
Sorry, forgot to close the <label> tag on line 10:
 
echo '<label for "fileindex">Index of file to be deleted: <input type="text" name="fileindex" id="fileindex" value="' . $_POST['fileindex'] . '" /></label>';

Open in new window

0
 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
This is the form:

<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
<input type="text" name="filenumber" value="" />
<input type="submit" name="submit" value="Submit" />
</form>

This isthe php code at the top of the same page:

<?php
if isset($_POSR['submit']){
  $number=$_POST['filenumber'];
  $fname="F:\MyFolder\" . $number . "\testfile.txt";
  unlink($fname);
  echo "File deleted."
}
?>

Cheers
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 30

Expert Comment

by:Marco Gasi
Comment Utility
Oooops: didn't refresh...
0
 

Author Closing Comment

by:einstein10
Comment Utility
Thank you so much! You have done a great job.
0
 
LVL 17

Expert Comment

by:OmniUnlimited
Comment Utility
No problem.  Best of luck to you on your project!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now