Jump to content

[Joomla 1.7] Upload files using JFTP

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
Into a view of my component I have a form with a file field, I have to upload that file (jpg) using FTP.

Here is how I do
jimport('joomla.client.ftp');
$app =& JFactory::getApplication();
        
$host = $app->getCfg('ftp_host');
$port = $app->getCfg('ftp_port');
$options = null;
$user = $app->getCfg('ftp_user');
$pass = $app->getCfg('ftp_pass');
$root = $app->getCfg('ftp_root');

$ftp = JFTP::getInstance($host, $port, $options, $user, $pass);
$file_1 = date('YmdHis').'-'.$autore.'-'.$titolo.'-1c1.jpg';

//code to chenge dir and create folder if not existing (this code works)
//I've checked the correct position printing $ftp->pwd()

//upload file
$upload = $ftp->store($files['file1']['tmp_name'], $file_1);

//$files['file1']['tmp_name'] contains the path and name for the uploaded file: /tmp/phpQfBT6o

exit(print_r($upload)); //this says 1, so the store should succeed, but inside the folder there isn't the file
Which is the problem? Maybe it is not correct to specify the temp file?
How do I have to do to correctly upload the file?

#2
Alhazred

Alhazred

    Learning Programmer

  • Members
  • PipPipPip
  • 99 posts
That "1" didn't mean "true" it was because of the print_r().

The store() fails.

I've tried to put this line in place of the store()
$ftp->create('test.txt');
and it fails

then I've tried
$ftp->mkdir('test');
and this succeed, the folder is created.

Why can't I create or store files?
Since the folder is created, that means that I have the rights to write into that folder.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users