Reputation: 3277
I'm trying to move an uploaded file inside my server on my Cpanel hosting. I am using the PHP function move_uploaded_file, but how do I know the exact path of my Server?
I tried using this syntax:
move_uploaded_file($filelocation, http://website.com/thisfolder/filename.txt);
i do know that my file location variable is outputting correctly as I could see that it goes into var/ directory of the server.
I want the path in my filemanager that has the public_html folder.
/ServerName1/ServerName2/public_html/Folder1/thisfolder
How do I place it into the correct directory?
Upvotes: 0
Views: 1769
Reputation: 1589
<?php
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
?>
A sample code of how to upload to a directory. You can find more examples here : https://www.php.net/move_uploaded_file
Upvotes: 1