psyberweb posted on 2008-12-09 02:58:44 #
hi,
ive successfully manage to use your code, but is there a way to rename it after uploading the file. i guess its with the use of CURLOPT_POSTQUOTE, however when i try to use it i couldnt make it work. could you possibly give a working modification of your code with a rename feature.
thanks and cheers!
The most popular forum posts:
Comments / discussions
psyberweb posted on 2008-12-09 03:06:40 #
$ch = curl_init();
$localfile = $_FILES['fuploadfile']['tmp_name'];
$buf[0] = "RNFR $localfile";
$buf[1] = "RNTO newname";
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://'.$_FILES['fuploadfile']['name']);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_POSTQUOTE, $buf);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
} else {
$error = 'File upload error.';
}
thats what i tried above but unsuccessful though.
Olaf posted on 2008-12-09 05:42:09 #
Hi no it's not the "post" option.
Just enter the name here:
curl_setopt($ch, CURLOPT_URL, 'ftp://'.$_FILES['fuploadfile']['name']);
and post the data from the upload.
psyberweb posted on 2008-12-09 16:12:44 #
hmm i tried changing the name to a different one, but this time it does not upload the file to the remote server? any ideas? also if you can help me about the file delete command too. thanks.
Olaf posted on 2008-12-09 16:18:59 #
is the above code you're using? if yes start again with my example snippet
psyberweb posted on 2008-12-09 19:03:22 #
im actually using your code now, it can upload to the remote server, but i have problem renaming and deleting it. can you help me on this please..thanks in advance.
Olaf posted on 2008-12-09 22:07:50 #
The code above is not exactly my script.
Which file do you need to remove? after upload to the server the file is NOT stored on the web server. We use temp upload file a data and the original file name as path/filename for the transfer to the ftp server.
this should work:
if (!empty($_FILES['upload']['name'])) {
$ch = curl_init();
$localfile = $_FILES['upload']['tmp_name']; // the data (file is not stored
$fp = fopen($localfile, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://ftp_login:password@ftp.domain.com/somepath/my_new_file_name.txt');
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$error = 'File uploaded succesfully.';
} else {
$error = 'File upload error.';
}
} else {
$error = 'Please select a file.';
}
psyberweb posted on 2008-12-12 18:59:45 #
hi thanks a lot! youre a big help, however im not done yet, the last thing would be the delete, how am i able to delete the renamed file i created? thanks!
Olaf posted on 2008-12-12 20:20:36 #
this should work:
function del_temp_file($file) {
$delete = @unlink($file);
clearstatcache();
if (@file_exists($file)) {
$filesys = eregi_replace("/","\\",$file);
$delete = @system("del $filesys");
clearstatcache();
if (@file_exists($file)) {
$delete = @chmod ($file, 0644);
$delete = @unlink($file);
$delete = @system("del $filesys");
}
}
}
psyberweb posted on 2008-12-13 07:13:17 #
hi olaf thanks for the help, however i already know the stuff you posted. what im referring was about deleting the file using curl, i only have ftp access to the server, so thats my only option. thanks!
Olaf posted on 2008-12-13 07:25:14 #
ooh ok, than you need to send an ftp/linux command, check this tutorial (how I use curl to create a directory)
http://www.web-development-blog.com/archives/create-custom-backups-from-your-website-using-curl/