Jump to content

Recommended Posts

Hi All,

I have setup an apache server on XP with simple functionalities like upload, download and delete. I am done with upload and download part. I dont know how to delete files. I know about unlink. But I have failed to implement it in my situation. In my situation, all files are displayed in directory called uploads, the path is as under:

http://localhost:8085/test/Upload/uploaddocs/ (when this is entered in browser you can view all files uploaded).

If I need to delete any selected file, How to go about it? I have spent 3 days working on it. I know about unlink but I have failed to figure it out how to use it in my situation.KIndly help me.

 

Ejaz

 

to delete a file, just do something like this

<?php
$file = "test.txt";
if (!unlink($file))
  {
  echo ("Error deleting $file");
  }
else
  {
  echo ("Deleted $file");
  }
?>

 

that is assuming that the file test.txt is in the same directory as the script running. if its not you have to use the absolute or relative path to the file. what does your code look like now

the code is exactly the same as you have mentioned. But there are 2 problems:

1) I want the file name to be selected by the user accessing my server. So i cant specify the file name. It should be passed as a paramter on click or if there is any other suitable way (and I dont know how to do that).

2) This piece of code is working fine but only for the file name specified. there are many files listed on the server. If some user want to delete one file he wont be having access to the unlink code to specify the filename. I want it to work as if as a user you click on a file to delete, it pops up a message asking Are you sure you want to delete file? and on pressing ok it should remove it from the server

 

Need you help..

pass the filename as a post variable? if necessary pass the folder path relative to the script itself also, but you only really need to do that if the the files that want to be deleted exist in different directories. The confirmation popup can be done with javascript.

I am done with the confirmation popup. But I dont know how to pass filename through post. The files are displayed as follow as href (automatically generated as a result of upload)

 

Index of /test/Upload/uploaddocs

 

Parent Directory

Installation Guide for Apache 2.2.13.docx

Installation_Guide_for_Apache_2.2.13.pdf

MIC_Pilot1000_Requirement_Specification.doc

MobidiaMeasurementTool Test Plan Result.xls

Olympic memo AEP.pdf

del.php

delete.php

delete1.php

delete2.php

delete3.php

flowplayer-3.1.3/

pic.jpg

sample.xlsx

 

Now I want that if some one clicks on any file, its should pop up a message and then delete it?

Kindly give some guidance on how to pass the file name since the source code of this page is automatically generated (which cant be modified)which can be viiewed as right click View Source:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<html>

<head>

  <title>Index of /test/Upload/uploaddocs</title>

</head>

<body>

<h1>Index of /test/Upload/uploaddocs</h1>

<ul><li><a href="/test/Upload/"> Parent Directory</a></li>

<li><a href="Installation%20Guide%20for%20Apache%202.2.13.docx"> Installation Guide for Apache 2.2.13.docx</a></li>

<li><a href="Installation_Guide_for_Apache_2.2.13.pdf"> Installation_Guide_for_Apache_2.2.13.pdf</a></li>

<li><a href="MAG%20Installation,%20Reference,%20and%20Miscellaneous%20Linux%20Commands(build).doc"> MAG Installation, Reference, and Miscellaneous Linux Commands(build).doc</a></li>

<li><a href="MAG%20Team%20Code%20Review%20Process.doc"> MAG Team Code Review Process.doc</a></li>

<li><a href="Olympic%20memo%20AEP.pdf"> Olympic memo AEP.pdf</a></li>

<li><a href="del.php"> del.php</a></li>

<li><a href="delete.php"> delete.php</a></li>

<li><a href="delete1.php"> delete1.php</a></li>

<li><a href="delete2.php"> delete2.php</a></li>

<li><a href="delete3.php"> delete3.php</a></li>

<li><a href="flowplayer-3.1.3/"> flowplayer-3.1.3/</a></li>

<li><a href="pic.jpg"> pic.jpg</a></li>

<li><a href="sample.xlsx"> sample.xlsx</a></li>

</ul>

</body></html>

 

Why can't you modify the source? You could make the links go to the delete page (obviously, have an onclick attribute for your popup) and pass the filename as a get variable. for example, a link may look like this

<a href="delete.php?page=Installation_Guide_for_Apache_2.2.13.pdf">Installation_Guide_for_Apache_2.2.13.pdf</a>

 

 

My upload.html code is:

<html>

<body>

<form enctype="multipart/form-data" action="upload_file.php" method="POST">

Choose a file to upload: <input name="uploadedfile" type="file" /><br />

<input type="submit" value="Upload File" />

<a href="uploaddocs/"><h1>Documents</h1></a>

</form>

</body>

</html>

upload_file.php and the print screen of once file is uploaded(the page showing directory in which files are uploaded) are attached with the mail. Kindly tell me how to get that href link in there with every file that is uploaded?

 

Kindly help me.

 

 

 

[attachment deleted by admin]

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.