使用url参数上传PHP文件 [英] PHP File Upload using url parameters

查看:51
本文介绍了使用url参数上传PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用php和参数中的文件名(而不是使用提交表单)将文件上传到服务器,就像这样:

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>  

感谢您的帮助

推荐答案

Image Upload Via url:
//check
$url = "http://theonlytutorials.com/wp-content/uploads/2014/05/blog-logo1.png";
$name = basename($url);
try {
    $files = file_get_contents($url);
    if ($files) {
        $stored_name = time() . $name;
        file_put_contents("assets/images/product/$stored_name", $files);
    }
}catch (Exception $e){
}

这篇关于使用url参数上传PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆