Well, honestly, I do not like while loops, so I would go with scandir() function in php that returns an array of all files. Then I will manipulate the array and upload file by file, rather than complete dir.
Also, I would like to use copy instead of move and once copy is successful, I would go with delete, calling another function.
But from the errors you get, I think the problem is here
$from = @fopen("$local_dir$files", 'r+');
I think this should look like
$from = @fopen("$local_dir/$files", 'r+');