PHP File Upload using url parameters

Posted by Arthur on Stack Overflow See other posts from Stack Overflow or by Arthur
Published on 2011-02-20T23:09:06Z Indexed on 2011/02/20 23:25 UTC
Read the original article Hit count: 289

Filed under:
|
|
|

Is there a way to upload a file to server using php and the filename in a parameter (instead using a submit form), something like this:

myserver/upload.php?file=c:\example.txt

Im using a local server, so i dont have problems with filesize limit or upload function, and i have a code to upload file using a form

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<body>
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" enctype="multipart/form-data">
    File to upload:
    <table>
      <tr><td><input name="upfile" type="file"></td></tr>
      <tr><td><input type="submit" name="submitBtn" value="Upload"></td></tr>
    </table>  
  </form>
<?php    
if (isset($_POST['submitBtn'])){

    // Define the upload location
    $target_path = "c:\\";

    // Create the file name with path
    $target_path = $target_path . basename( $_FILES['upfile']['name']); 

    // Try to move the file from the temporay directory to the defined.
    if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['upfile']['name']). 
             " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
}
?>
</body>  

Thanks for the help

© Stack Overflow or respective owner

Related posts about php

Related posts about file