Sarath Sp Sarath Sp - 6 months ago 23
PHP Question

Read write with multiple file upload through Lan in Wamp

Iam working on an inhouse project where there is a multi part file uploading function is built. Iam running a windows 7 with wamp 2.5

The multiple file upload works perfect and the files are being uploaded into the specified directories. The upload directory has been shared on a Lan network so that the other users can also access the uploaded file. But the uploaded files cannot be viewed from another computer connected in the Lan. There are lot of folder creations and the Lan systems are able to browse through the folders. But the files are not able to be viewed. Iam pasting the code below

//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

}
}
}
}

Answer

I have found the answer myself

The files uploaded through the wamp will never get the full permission from the windows. The only way out is to add a code to copy the uploaded file by renaming it with an underscore prefix or something like that so that the new file will get the full permission and will be readable and editable by the other windows users connected to the Lan. The code will be somewhat like below (in connection with the code mentioned in the question) //Loop through each file 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);