Search code examples
phpnetwork-programmingsavehost

PHP save / store file to remote server?


Is it possible for users to save / store their photos and videos to remote server, not localhost without using FTP but using web interface (php)?

If so, how to do it?


Solution

  • Set a new form:

    <form enctype="multipart/form-data" action="uploader.php" method="POST">
    Choose a file to upload: <input name="file" type="file" /><br />
    <input type="submit" value="Upload File" />
    </form>
    

    In uploader.php you should have someting like:

    $folder = "uploads/";
    
    $path = $folder . basename( $_FILES['file']['name']); 
    
    if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
        echo "The file ".  basename( $_FILES['file']['name']). " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    

    This is one of the simplest methods to upload a file to a server. However you might want to customize and add some more information to your file upload form.