通过Wamp中的Lan读取多个文件的写入

时间:2016-05-13 17:28:36

标签: php file-upload

我正在开发一个内部项目,其中有一个多部分文件上传功能。我运行Windows 7与wamp 2.5

多文件上传工作正常,文件正在上传到指定目录。上传目录已在Lan网络上共享,以便其他用户也可以访问上传的文件。但是无法从Lan中连接的另一台计算机查看上传的文件。有很多文件夹创建,Lan系统可以浏览文件夹。但是无法查看文件。我粘贴下面的代码

//File upload section
    if(count($_FILES['upload']['name']) > 0){

if (!file_exists('Other_Orders/'.$currentyear.'/'.$currentmonth.'/'.$currenttime.'/'.$ordernumber.'_'.$customername)) 
                                            {
mkdir('Other_Orders/'.$currentyear.'/'.$currentmonth.'/'.$currenttime.'/'.$ordernumber.'_'.$customername, 0777);
                                            }   
if (!file_exists('Other_Orders/'.$currentyear.'/'.$currentmonth.'/'.$currenttime.'/'.$ordernumber.'_'.$customername.'/01_'.$product)) 
                                            {
mkdir('Other_Orders/'.$currentyear.'/'.$currentmonth.'/'.$currenttime.'/'.$ordernumber.'_'.$customername.'/01_'.$product, 0777);
                                                }   
$pathtoupload= "Other_Orders/".$currentyear.'/'.$currentmonth.'/'.$currenttime.'/'.$ordernumber.'_'.$customername."/01_".$product;

    //Loop through each file
    for($i=0; $i<count($_FILES['upload']['name']); $i++) {
      //Get the temp file path
        $tmpFilePath = $_FILES['upload']['tmp_name'][$i];

        //Make sure we have a filepath
        if($tmpFilePath != ""){

            //save the filename
            $shortname = $_FILES['upload']['name'][$i];

            //save the url and the file
            $filePath = $pathtoupload."/" . $_FILES['upload']['name'][$i];

            //Upload the file into the temp dir
            if(move_uploaded_file($tmpFilePath, $filePath)) {

                $files[] = $shortname;
                //insert into db 
                //use $shortname for the filename
                //use $filePath for the relative url to the file

            }
          }
    }
    }

1 个答案:

答案 0 :(得分:0)

我自己找到了答案

通过wamp上传的文件永远不会获得Windows的完全许可。唯一的出路是添加一个代码来复制上传的文件,方法是用下划线前缀或类似名称重命名,以便新文件获得完全权限,并且连接到Lan的其他Windows用户可以读取和编辑。代码有点像下面(与问题中提到的代码有关)         //遍历每个文件         for($ i = 0; $ i

        //Make sure we have a filepath
        if($tmpFilePath != ""){

            //save the filename
            $shortname = $_FILES['upload']['name'][$i];
            $share_name = "_".$shortname;

            //save the url and the file
            $filePath = $pathtoupload."/" . $_FILES['upload']['name'][$i];

            //Upload the file into the temp dir
            if(move_uploaded_file($tmpFilePath, $filePath)) {

                $files[] = $shortname;


                $source_dir = $pathtoupload."/".$shortname;
                $target_dir = $pathtoupload."/".$share_name;
                copy($source_dir,$target_dir);
                unlink($source_dir);