douti6740 2011-11-28 00:25
浏览 49
已采纳

如何允许用户选择将文件上载到的位置?

I have a basic upload form

<html>
<head>
<title>Upload a File</title>
</head>
<body>
<font face=verdana size=2>
<form enctype="multipart/form-data" method="post" action="upload_file.php">
<input type="hidden" name="MAX_FILE_SIZE" value="25000">

<p><strong>File to Upload:</strong><br>
<input type="file" name="our_file" size="30"></p>

<P><input type="submit" name="submit" value="Upload File"></p>

</form>
</font></body>
</html>

And the php file

<?

if ($our_file != "") {

    copy($our_file, "upload/$our_file_name") or die("Couldn't Upload the file!");  

} else {

    die("No input file specified");
}

?>

<html>
<head>
<title>Successful File Upload!</title>
<body><font face=verdana size=2>

<B>Success!</B>

<P>You sent: <? echo "$our_file_name"; ?>, a <? echo "$our_file_size"; ?> 
byte file with a mime type of <? echo "$our_file_type"; ?>.</p>

</font></body>
</html>

I would like the user to be able to choose what directory he uploads the file to. I assume I would need a form for the HTML side of it but I don't know what to add in the PHP. Any help?

  • 写回答

2条回答 默认 最新

  • dscss8996 2011-11-28 00:31
    关注

    Assuming you only have a fixed number of directories, include a select in your HTML.

    @thephpdeveloper, As long as your permissions are set right for your directories, I don't think selecting where you upload is going to be anymore dangerous than any other upload. I am by no means a security expert. Just make sure you're preventing injection, etc.

    <select name="selectDir">
        <option value="1">This Directory</option>
        <option value="2">That Directory</option>
    </select>
    
    
    // on your submit
    if( $_POST['selectDir'] === '1' ){
        $dir = './thisdir/';
    }elseif( $_POST['selectDir'] === '2' ){
        $dir = './thatdir/';
    }else{
        die('You did not enter a valid value');
    }
    
    if ($our_file != "") {
        copy($our_file, $dir."".$our_file_name) or die("Couldn't Upload the file!");      
    }else{
        die("No input file specified");  
    }   
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图