Re: Deleting a file after download/upload
| From: | Parham Doustdar | Date: | Thu, 25 Jun 2009 12:04:44 +0000 |
| Subject: | Re: Deleting a file after download/upload | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-294570@lists.php.net to get a copy of this message | ||
Hi there Shawn,
Thank you for your help. That works.
--
---
Contact info:
Skype: parham-d
MSN: fire_lizard16 at hotmail dot com
email: parham90 at GMail dot com
"Shawn McKenzie" <nospam@mckenzies.net> wrote in message
news:EE.3D.36467.C02614A4@pb1.pair.com...
> Parham Doustdar wrote:
>> Hi there,
>> I am writing a PHP FTP client for my project. I want to put a "download"
>> option and an "upload"" option, but I don't know how. My problem is
this:
>> How can I make the server the PHP script is on delete the file after
>> uploading it to the SFTP, or after the user has finished downloading it
>> from the server the PHP script is on?
>> Let me put the question this way.
>> My server connects to an FTP. Then, it downloads a file from the FTP, and
>> then sends me the link to that temperary file on the server. Now, when I
>> download it from my server, my script should delete the file. How can I
>> make it wait until the download of the file is finished?
>> Same goes for uploading.
>> Thanks!
>>
>
> Well if you write a download script, then you can delete it at the end
> and it won't be deleted until after the download completes:
>
> //Do your ftp from remote to local'/path/to/file.ext'
> exec('ftp_get.sh remotefile.ext /path/to/file.ext);
> //or
> $conn_id = ftp_connect($ftp_server);
> $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
> ftp_gett($conn_id, '/path/to/file.ext', $server_file, FTP_BINARY)
> ftp_close($conn_id);
>
> <?php
> //send proper headers for download
> readfile('/path/to/file.ext');
>
> unlink('/path/to/file.ext');
> ?>
>
> For upload, depending upon how you're doing it, a call to unlink()
> shouldn't execute until your FTP is done and exited:
>
> <?php
> //User uploads file to '/path/to/file.ext'
>
> exec('ftp_put.sh /path/to/file.ext);
> //or
> $conn_id = ftp_connect($ftp_server);
> $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
> ftp_put($conn_id, $server_file, '/path/to/file.ext', FTP_BINARY)
> ftp_close($conn_id);
>
> unlink('/path/to/file.ext');
> ?>
>
> --
> Thanks!
> -Shawn
> http://www.spidean.com