When uploading (writing) a file you must use an absolute path, not a relative one.
If, like me, you want to use a relative path, you can use the following code:
$fh=fopen("ssh2.sftp://$sftp".ssh2_sftp_realpath($sftp,".")."/fileinmyhomedir.txt");
When uploading (writing) a file you must use an absolute path, not a relative one.
If, like me, you want to use a relative path, you can use the following code:
$fh=fopen("ssh2.sftp://$sftp".ssh2_sftp_realpath($sftp,".")."/fileinmyhomedir.txt");