cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

Re: Re: Deleting a file using curl and php

From: Adam Richardson <adam_at_envisionic.com>
Date: Mon, 1 Sep 2008 18:25:25 -0400

Stephen,

I just wanted to say thank you, your code worked. That was a big help.

I've developed a class for my framework that is helpful in situations when
I'm developing code for a client who's account is on a shared server without
suPHP or PHPSuExec. Now on those types of servers, instead of having to
change permissions of an upload directory to 777 or store the files to a DB
(what I've done in the past) or just avoid file uploads altogether, the code
simply uses curl to FTP in using an account restricted to the directory
where files are created and performs any writes OR (thanks to you)
deletions. I just call save() or delete() and the code makes sure the best
option is executed (standard file operations or the CURL FTP operations.)

Thank you very much for your example,

Adam

Date: Sun, 31 Aug 2008 16:55:02 -0400
From: "Stephen Pynenburg" <spynenburg_at_gmail.com>
Subject: Re: Deleting a file using curl and php
To: "curl with PHP" <curl-and-php_at_cool.haxx.se>
Message-ID:
       <bc22ecd40808311355v3edaf5few72f4190c16fe89a1_at_mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

I'm pretty sure you have to use something like this:
<?PHP
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "ftp://user:pwd@ftp.site.com");
curl_setopt($ch, CURLOPT_QUOTE, array("DELE /path/to/file.ext"));
curl_exec($ch);
?>
Although I've never actually done it myself. Note that you have to use
commands compliant with this RFC: http://www.faqs.org/rfcs/rfc959.html
As opposed to the shell/command line options you're probably used to.

-Stephen

2008/8/31 Adam Richardson <adam_at_envisionic.com>

> Hi, I've searched on google and didn't see anything on how to do this.
>
> I'm aware of code like the following that allows me to update or save a
> file to a server using ftp within curl:
>
>
> <?php
> //
> // A simple PHP/CURL FTP upload to a remote site
> //
>
> $ch = curl_init();
> $localfile = "me-and-my-dog.jpg"
>
> $fp = fopen ($localfile, "r");
>
> // we upload a JPEG image
> curl_setopt($ch, CURLOPT_URL,
> "
ftp://mynamw:mypassword@ftp.mysite.com/path/to/destination.jpg");
> curl_setopt($ch, CURLOPT_UPLOAD, 1);
> curl_setopt($ch, CURLOPT_INFILE, $fp);
>
> // set size of the image, which isn't _mandatory_ but helps libcurl to do
> // extra error checking on the upload.
> curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
>
> $error = curl_exec ($ch);
>
> // check $error here to see if it did fine or not!
>
> curl_close ($ch);
> ?>
>
> How do I alter this code to delete a file on a remote server?
>
> Thank you for your help,
>
> Adam
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-09-02