How to delete a file in my web server via php

This is a discussion on How to delete a file in my web server via php within the PHP Language forums, part of the PHP Programming Forums category; Hi to all, that's my question I have mysql database and a web page to upload files to my ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-22-2007
marce1972
 
Posts: n/a
Default How to delete a file in my web server via php

Hi to all, that's my question I have mysql database and a web page to
upload files to my webpage, I know how to delete them from the
database, but didnt find the code to delete them from the web server.
Please help me with this code.

Regards

Marcelo Fabiani

Reply With Quote
  #2 (permalink)  
Old 01-22-2007
Janwillem Borleffs
 
Posts: n/a
Default Re: How to delete a file in my web server via php

marce1972 wrote:
> Hi to all, that's my question I have mysql database and a web page to
> upload files to my webpage, I know how to delete them from the
> database, but didnt find the code to delete them from the web server.
> Please help me with this code.
>


The only way to do this through HTTP is to create a remote script that
accepts parameters and uses these to select and delete the file. There's
also a HTTP DELETE method, but I have never encountered a server which
supports it.


JW


Reply With Quote
  #3 (permalink)  
Old 01-22-2007
Floortje
 
Posts: n/a
Default Re: How to delete a file in my web server via php

Janwillem Borleffs schreef:
> marce1972 wrote:
>> Hi to all, that's my question I have mysql database and a web page to
>> upload files to my webpage, I know how to delete them from the
>> database, but didnt find the code to delete them from the web server.
>> Please help me with this code.
>>

>
> The only way to do this through HTTP is to create a remote script that
> accepts parameters and uses these to select and delete the file. There's
> also a HTTP DELETE method, but I have never encountered a server which
> supports it.
>
>
> JW


shortest way :
@unlink($file);

Make sure to check the input first

--
Arjen
http://www.hondenpage.com
Reply With Quote
  #4 (permalink)  
Old 01-22-2007
Toby Inkster
 
Posts: n/a
Default Re: How to delete a file in my web server via php

Janwillem Borleffs wrote:

> The only way to do this through HTTP is to create a remote script that
> accepts parameters and uses these to select and delete the file. There's
> also a HTTP DELETE method, but I have never encountered a server which
> supports it.


Apache does, though you need to do a lot of setup to get it to work.
WebDAV is a bit easier to set up, and better supported at the client end.

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Reply With Quote
  #5 (permalink)  
Old 01-22-2007
marce1972
 
Posts: n/a
Default Re: How to delete a file in my web server via php


Floortje wrote:
> Janwillem Borleffs schreef:
> > marce1972 wrote:
> >> Hi to all, that's my question I have mysql database and a web page to
> >> upload files to my webpage, I know how to delete them from the
> >> database, but didnt find the code to delete them from the web server.
> >> Please help me with this code.
> >>

> >
> > The only way to do this through HTTP is to create a remote script that
> > accepts parameters and uses these to select and delete the file. There's
> > also a HTTP DELETE method, but I have never encountered a server which
> > supports it.
> >
> >
> > JW

>
> shortest way :
> @unlink($file);
>
> Make sure to check the input first
>
> --
> Arjen
> http://www.hondenpage.com


Do I rite this on my php code as you wrote it?

$nom=$_POST['numero'];
$sql="DELETE FROM canciones WHERE idcancion='$nom';";
mysql_query($sql) or die ("problema con borrado");
$arch=$_POST['ref'];
@unlink($arch);

Is this correct
Thanks I'll download the other option webdav too to see if it works

regards

Marcelo

Reply With Quote
  #6 (permalink)  
Old 01-22-2007
Ruben van Engelenburg
 
Posts: n/a
Default Re: How to delete a file in my web server via php

marce1972 wrote:

> Do I rite this on my php code as you wrote it?
>
> $nom=$_POST['numero'];
> $sql="DELETE FROM canciones WHERE idcancion='$nom';";
> mysql_query($sql) or die ("problema con borrado");
> $arch=$_POST['ref'];
> @unlink($arch);
>
> Is this correct
> Thanks I'll download the other option webdav too to see if it works


No, as Arjen already pointed out: check the input. This means you should
check the value of $_POST['ref'], because if you don't the user will be
able to delete any file the webserver has writing rights to.

Ruben.
Reply With Quote
  #7 (permalink)  
Old 01-22-2007
Floortje
 
Posts: n/a
Default Re: How to delete a file in my web server via php

Ruben van Engelenburg schreef:
> marce1972 wrote:
>
>> Do I rite this on my php code as you wrote it?
>>
>> $nom=$_POST['numero'];
>> $sql="DELETE FROM canciones WHERE idcancion='$nom';";
>> mysql_query($sql) or die ("problema con borrado");
>> $arch=$_POST['ref'];
>> @unlink($arch);
>>
>> Is this correct
>> Thanks I'll download the other option webdav too to see if it works

>
> No, as Arjen already pointed out: check the input. This means you should
> check the value of $_POST['ref'], because if you don't the user will be
> able to delete any file the webserver has writing rights to.


One way to do it:
check if page is listed in the db
$sql = "SELECT id,page FROM $table WHERE id = '".intval($_POST['id'])."'";

if that query gives one result then execute your code


--
Arjen
http://www.hondenpage.com
Reply With Quote
  #8 (permalink)  
Old 01-22-2007
Floortje
 
Posts: n/a
Default Re: How to delete a file in my web server via php

Floortje schreef:
> Ruben van Engelenburg schreef:
>> marce1972 wrote:
>>
>>> Do I rite this on my php code as you wrote it?
>>>
>>> $nom=$_POST['numero'];
>>> $sql="DELETE FROM canciones WHERE idcancion='$nom';";
>>> mysql_query($sql) or die ("problema con borrado");
>>> $arch=$_POST['ref'];
>>> @unlink($arch);
>>>
>>> Is this correct
>>> Thanks I'll download the other option webdav too to see if it works

>>
>> No, as Arjen already pointed out: check the input. This means you
>> should check the value of $_POST['ref'], because if you don't the user
>> will be able to delete any file the webserver has writing rights to.

>
> One way to do it:
> check if page is listed in the db
> $sql = "SELECT id,page FROM $table WHERE id = '".intval($_POST['id'])."'";
>
> if that query gives one result then execute your code


And I mean execute your code with the results from the query :-) not
from the user input.


--
Arjen
http://www.hondenpage.com
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 05:25 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0