I was getting 2 warnings while trying to use the php move_uploaded_file function. Here I show you what these warnings are and how to fix it.
Warning: move_uploaded_file(/public_html/upload) [function.move-uploaded-file]: failed to open stream: No such file or directory in /folder/myscript.php on line X
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/filename’ to ‘/publci_html/upload’ in /folder/myscript.php on line X
To make a long story short, I’ll show you the code that caused this warnings and how to fix it.
$dirpath = dirname(getcwd())
This is what I used initially to get the directory path to my /public_html/upload folder. $dirpath will contain
$dirpath = realpath(dirname(getcwd()))
Since I’m on a shared hosting environment, the right way of getting move_uploaded_file to work is using this as the destination:
realpath(dirname(getcwd())) returns something like:
Hope this helps. Comments welcomed.