Unable to share a folder in htdocs [Answered]

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Unable to share a folder in htdocs [Answered]

Postby MikeSpider » 10. July 2012 16:58

Hi guys,
I'm trying to share a folder inside my htdocs, I need for people to be able to edit it through the browser.
It's telling me :" your folder can't be shared"

I'm running on windows 7 Home premium.
Any help will be much appreciated.

Thanks,
Mike
MikeSpider
 
Posts: 6
Joined: 10. July 2012 16:53
Operating System: Windows 7 home edition

Re: Unable to share a folder in htdocs

Postby JonB » 10. July 2012 17:29

Uh Mike, I don't think it works quite like that.

There's something 'close' called Webdav

http://en.wikipedia.org/wiki/WebDAV

and its built into XAMPP

Although I don't know anything about version 1.6.0 of XAMPP (Is that what you are really running?)

Windows has a non-browser version called 'web folders' it works through Windows Explorer.


Good Luck
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Unable to share a folder in htdocs

Postby MikeSpider » 10. July 2012 18:58

My xampp version is 1.7.3 I Made a php app that runs localy on the browser, it can access files and open them, but can't modify them.
I know it has something to do with the permissions.
So there's no way I can modify files kept in my localhost(htdocs)?

PS: It seems that the WebDAV is for the web(online) purposes only?
My app runs offline in localhost, will it work?

Thanks for your reply,
Mike
MikeSpider
 
Posts: 6
Joined: 10. July 2012 16:53
Operating System: Windows 7 home edition

Re: Unable to share a folder in htdocs

Postby JonB » 10. July 2012 19:23

My xampp version is 1.7.3 I Made a php app that runs localy on the browser, it can access files and open them, but can't modify them.


There are no permissions issues that I can think of in that scenario. You do know that there are different modes of opening files in PHP, right?

I'm going to defer to our PHP guru, Altrea, on this one.

To be honest, I'm totally confused why you would want to do this 'locally' through a browser interface.

php 'can' run without a browser, it just can't do much for output in that mode, that's how some of the XAMPP utilities used to work.

Good Luck
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Unable to share a folder in htdocs

Postby MikeSpider » 10. July 2012 22:07

I'm pretty much stuck here, looked everywhere in the internet didn't find anything at all. I just went manually on my folders inside the xampp htdocs, and tried to share with everyone, but just got the same windows message " your folder can't be shared!" seems like a nightmare to me, cause my application depends on sharing a folder which contains some documents. What it does( the app) is: moves (copies) documents from a folder outside the localhost (in my desktop) to a folder inside the htdocs inside my project and organizes files based on their category (documents, contracts, invoices etc), then the admin can perform a search based on category and all the files appear listed. When he clicks the files it opens but in read mode only! I already tried "fopen($file, a)" it takes forever and does not open the doc. and now i see that it does not allow to write or modify files.

Is there any way to override this rule?

Anyone please help! :(
MikeSpider
 
Posts: 6
Joined: 10. July 2012 16:53
Operating System: Windows 7 home edition

Re: Unable to share a folder in htdocs

Postby JonB » 11. July 2012 02:53

Hi Mike -

The desktop is a privileged area in Windows Authentication, you are dealing with an OS issue, not a XAMPP one.

Maybe Altrea will have an insight.

Good Luck
8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Unable to share a folder in htdocs

Postby MikeSpider » 11. July 2012 13:21

Thanks for your reply,
I thought it to be xampp problem, because i can share any other folder. the ones I cannot share are the ones inside the htdocs in xampp directory.

Thanks,
Mike
PS: who is Altrea?
MikeSpider
 
Posts: 6
Joined: 10. July 2012 16:53
Operating System: Windows 7 home edition

Re: Unable to share a folder in htdocs

Postby JonB » 11. July 2012 13:35

Altrea is the other AF global moderator currently working, he is quite expert with PHP.
memberlist.php?mode=viewprofile&u=41947

I suspect the problems lie with the Windows properties of those files. You should 'examine' them and look at all their properties. I suspect when you move/copy a file from the desktop to a destination outside the Users hierarchy the file becomes a foreign object and therefore 'read-only'.

Good Luck.
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7

Re: Unable to share a folder in htdocs

Postby Altrea » 11. July 2012 17:49

Hi Mike,

Sorry, i have read your posts thrice and still have absolutely no idea how your script should work / is working.
Without knowing any part of your code i don't think that we can say anything about it which can be the truth.

MikeSpider wrote:I Made a php app that runs localy on the browser

Is that true? I don't know any browser or browser plugin which emulate or contains a full php interpreter. PHP scripts will not be processed directly by a browser. Browsers can request ressources which are builded from php scripts or maybe are the php sources itself, but in all of this cases php is executed by a webserver not the browser.

MikeSpider wrote:it can access files and open them

HOW do they access and open them by now? And which type of files?

MikeSpider wrote:but can't modify them.

What does "modify" mean? What do you want to modify exactly?

MikeSpider wrote:What it does( the app) is: moves (copies) documents from a folder outside the localhost (in my desktop) to a folder inside the htdocs inside my project

HOW does it move/copy the file?

MikeSpider wrote:I'm trying to share a folder

What does "share" mean? Which functionality is used (net use? windows share?)

MikeSpider wrote:It's telling me :" your folder can't be shared"

Where does this message come from (Windows message windows, your application, ... ?)

MikeSpider wrote:When he clicks the files it opens but in read mode only!

How does the Link look like (which URL is used)?

You see, many many questions.

best wishes,
Altrea

P.S.: If you are using XAMPP 1.7.3, you should bring your forum profile info up to date.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Unable to share a folder in htdocs

Postby MikeSpider » 11. July 2012 19:46

OK. I'm sorry for not posting the script b4.
It runs on Xampp.

The Page:
Code: Select all
<?php
require_once '../inc.php';
    // Setting variables to keep check box checked
    $contratosStatus = 'unchecked';
    $curriculosStatus = 'unchecked';
    $facturasStatus = 'unchecked';
     $contratosStatus2 = 'unchecked';
    $curriculosStatus2 = 'unchecked';
    $facturasStatus2 = 'unchecked';

// Search Button handler
if("Busca" == $_POST['submit']){
   
    $search = true;
    $_keyword = FilterData($_POST['keyword']);
    $_cat = FilterData($_POST['category']);
    if($_cat == "Contratos"){
        $contratosStatus = 'checked';
    }elseif($_cat == "Curriculos"){
        $curriculosStatus = 'checked';
    }elseif($_cat == "Facturas"){
        $facturasStatus = 'checked';
    }


   // create instance of class Document to fetch and  display items
    $query = new Document($_cat,$_keyword);
    $query->fetchDocs();
}


//Insert Function Handler
if("Inserir" == $_POST['submit'])
{
    $_desc = FilterData($_POST['description']);
    $_cat = FilterData($_POST['category']);
   
    if($_cat == "Contratos"){
        $contratosStatus2 = 'checked';
    }elseif($_cat == "Curriculos"){
        $curriculosStatus2 = 'checked';
    }elseif($_cat == "Facturas"){
        $facturasStatus2 = 'checked';
    }
           
         if("" != $_cat){
         if("" != $_FILES['file']['name'])
                {
           
           //Check for .exe files
            if(!preg_match("/.exe/", $_FILES['file']['name']))
            {
             
              // Create instance of Document class and Insert New Doc to db and move to folder
                $insert = new Document();
                $insert->Insert($_desc, $_cat, $_FILES);

                    if(true == $insert->Success())
                    {
                        $message =  "Arquivo " .$_desc ." inserido na base de dados.";

                    }

            }else{
                          $message = "Este tipo de ficheiro nao e permitido";
            }

                }else{
                            $message = "You need to choose a file!";
                }
           

    }else{
        $message = "You need to select a category!";
    }
}

?>
<?php adminheader();?>
   <!-- interface-->   

<div id="maincol">
        <br>                   
               
            <div align="center">
                                 
            <br>
                                        <?php if($message)echo $message; ?>

            <table id="first_tbl">
                <tr>
                    <td>

                              <!-- SEARCH BOX (FORM) -->
                                <div id="search_box">
                                    <h4>Buscar documento</h4>
                    <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
                        <table>
                            <tr>
                                <td>
                                    <input type="text" name="keyword" id="keyword" size="25" value="<?php echo $_keyword;?>">
                                </td>
                                <td>
                                    <input type="submit" name="submit" class="button" value="Busca">
                                </td>
                                </tr>         

                                    <input type="radio" name="category" id="category" value="Contractos" <?php echo $contratosStatus;?>> Contractos                                 
                                    <input type="radio" name="category" id="category" value="Curriculos" <?php echo $curriculosStatus;?>> Curriculos           
                                    <input type="radio" name="category" id="category" value="Facturas" <?php echo $facturasStatus;?>> Facturas                                           

                        </table>         

                    </form>
                        </div>
                    </td>
                    <td>

                    <div>
                        <h4>Inserir documento</h4>

                                      <!-- INSERT BOX (FORM) -->
                        <form method="post" action="<?php echo $_SERVER['PHPH_SELF'];?>" enctype="multipart/form-data">
                            <table>
                                    <tr>
                            <td>
                            <input type="file" name="file" id="file">
                            </td>     
                            </tr>

                                <tr>
                                    <td>
                                        <label for="description">Descricao</label>
                                            <input type="text" name="description" id="description" size="25" value="<?php echo $_desc; ?>">
                                    </td>
                                    <td>
                                        <input type="submit" name="submit" class="button" value="Inserir">

                                    </td>
                                </tr>


                                    <input type="radio" name="category" id="category" value="Contractos" <?php echo $contratosStatus2;?>> Contractos                                 
                                    <input type="radio" name="category" id="category" value="Curriculos" <?php echo $curriculosStatus2;?>> Curriculos           
                                    <input type="radio" name="category" id="category" value="Facturas" <?php echo $facturasStatus2;?>> Facturas     


                            </table>
                        </form>

            </div>
                    </td>
                </tr>
            </table>
               
                <?php if($search == true){ 

// AREA WHERE FILES WILL BE DISPLAYED
                   
                   if($query->data !=0){ ?>
            <br>
            <table>
                    <tr>
                        <th>Document</th>
                        <th>Descricao</th>
                        <th>Categoria</th>
                        <th>Data de arquivo</th>
                    </tr>
                       
              <?php foreach($query->data as $d){
                   $path ="../documentos/".$d['category']."/".$d['image']; ?>
                  <tr>
               
                        <td>
                            <?php if(preg_match("/\.doc$/",$d['image']) || preg_match("/\.docx$/",$d['image'])){
                                ?>                                         
                                        <a href="../application/getFilesDoc.php?file=<?php echo $path;?>"> 
                                             <img alt="" src="../images/word.jpg" width="40px" border="0px">
                            </a>
                                <?php    }else if(preg_match("/\.pdf$/",$d['image'])){ ?>
                           <a href="../application/getFilesPdf.php?file=<?php echo $path;?>">
                               <img alt="" src="../images/pdf.gif" width="40px" border="0px">
                            </a>
 
                                <?php  }else if(preg_match("/\.xls$/",$d['image'])){ ?>
                                       <a href="../application/getFilesExcel.php?file=<?php echo $path;?>">
                                            <img alt="" src="../images/excel.png" width="40px" border="0px">
                            </a>
                                     
                                  <?php  }else if(preg_match("/\.xlsx$/",$d['image'])){ ?>
                                       <a href="../application/getFilesExcel2.php?file=<?php echo $path;?>">
                                            <img alt="" src="../images/excel.png" width="40px" border="0px">
                            </a>
                             <?php  }else if(preg_match("/\.txt$/",$d['image'])){ ?>
                                       <a href="../application/getFilesText.php?file=<?php echo $path;?>">
                                            <img alt="" src="../images/text.png" width="40px" border="0px">
                            </a>
                                           
                                   <?php }else if(preg_match("/\.jpg$/",$d['image']) || preg_match("/\.jpeg$/",$d['image'])
                                    || preg_match("/\.png$/",$d['image']) || preg_match("/\.gif$/",$d['image'])
                                        || preg_match("/\.bmp$/",$d['image'])){?>
                            <a href="<?php echo $path;?>">
                                <img alt="" src="<?php echo $path;?>" width="40px" border="0px">
                            </a>
                                                                           
                                 <?php }?>
                           
                            </td>
                        <td>
                            <?php echo $d['description'];?>
                        </td>
                        <td>
                        <?php echo $d['category'];?>
                        </td>
                        <td>
                            <?php echo $d['date'];?>
                        </td>
                                             
                    </tr>             
               
                <?php } ?>
                     </table>

                    <?php } else{ echo "<p class='negative_msg'> A sua busca retornou 0 resultados.</p>";}
                   
                    }?>
            </div>           

        <br class="clear">
   
</div>
<?php adminfooter();?>



My Class functions:

Code: Select all

<?php

class Document{

    //create variables
    public $db;
    public $data;
    public $cat;
    public $keyword;
    private $success = false;
    private $file_check = false;

    //create db object instance
    public function  __construct($cat="",$keyword="") {
        $this->db = new DB();
        $this->cat = $cat;
         $this->keyword = $keyword;
    }


/* //////////////////////////FETCH FUNCTIONS///////////////////////////// */

    //fetch Files
    public function fetchDocs()
    {
        try{  //run query

                 
            if("" != $this->cat && "" != $this->keyword ){
                            $sql = "SELECT * FROM documents WHERE category='{$this->cat}'AND description LIKE '%{$this->keyword}%' ORDER BY date DESC ";

            }else if("" == $this->cat && "" != $this->keyword){
                               $sql = "SELECT * FROM documents WHERE  description LIKE '%{$this->keyword}%' ORDER BY date DESC ";
            }else if("" != $this->cat && "" == $this->keyword){
                              $sql = "SELECT * FROM documents WHERE category='{$this->cat}' ORDER BY date DESC ";
             
            }else{
            $sql = "SELECT * FROM documents ORDER BY date DESC ";
            }
            $result = $this->db->mysqli->query($sql);
                    //test result
                    if(!$result)
                    {       //error handler
                           throw new Exception("Query failed: " . $sql . " - " . $this->db->mysqli->error);

                    }else{
                           
   // display files
             while($p = $result->fetch_assoc()) {
            $this->data[] = array('id' =>$p['id'],
                                  'description' =>$p['description'],
                                  'category' => $p['category'],
                                  'image' => $p['image'],
                                  'date' => $p['date'],
                                  'update'=>"<a href='update-doc.php?id={$p['id']}&amp;d={$p['description']}&amp;c={$p['category']}&amp;i={$p['image']}'>Actualizar</a>",
                                  'delete' =>"<a href='home.php?id={$p['id']}&amp;action=delete' onclick='return(confirm(\"Tem a certeza?\"))'>Eliminar</a>",
                                  );


        }

        return $this->data;

                    }
                    //error handler
            } catch(Exception $e){
               echo("Message: " . $e->getMessage());
            }

    }

//function to insert / move documents to relevant folder(category)
public function Insert($desc, $cat,$image)
    {
        try{
                $_desc = $this->db->mysqli->real_escape_string($desc);
                $_cat = $this->db->mysqli->real_escape_string($cat);

               
                        if("" != $image['file']['name'] && 0 != $image['file']['size'])
                        {
                            $upload = true;
                            $img_name  = time() . $image['file']['name'];
                        }else{
                            $img_name = "noimage.jpg";
                        }
                        $sql = "INSERT INTO documents VALUES(NULL,'{$_desc}','{$_cat}','{$img_name}', NOW())";
                        $result = $this->db->mysqli->query($sql);

                        if(!$result)
                        {
                                throw new Exception("Query failed!" . $sql . " " . $this->db->mysqli->error);

                        }else{

                            if(true == $upload)
                            {
                              if(!is_dir("../documentos/". $_cat)){
                                    mkdir('../documentos/'.$_cat);
                              }
                                move_uploaded_file($image['file']['tmp_name'], '../documentos/'.$_cat.'/'.$img_name );
                            }

                            $this->success = true;
                        }
       

        } catch(Exception $e){
           echo("Message: " . $e->getMessage());
        }
    }

private function Success(){
  return $this->success;
}
}
?>
//end of class



Script to get open the document in it's own default windows application:

Code: Select all
<?php
if(!preg_match("/\.docx$/",$_GET['file'])) { exit; }
if(!file_exists(dirname(__FILE__)."/".$_GET['file'])) { exit; }
header("Content-type: application/vnd.ms-word");
header("Content-Length: ".filesize(dirname(__FILE__)."/".$_GET['file']));
header("Content-Disposition: attachment; filename=".$_GET['file']);
$fp = fopen(dirname(__FILE__)."/".$_GET['file'],'r');
if(!$fp) { exit; }
while(!feof($fp)) {
echo fread($fp, 4096);
ob_flush();
}
fclose($fp);

?>


I tried to change the
Code: Select all
$fp = fopen(dirname(__FILE__)."/".$_GET['file'],'r');

to
Code: Select all
$fp = fopen(dirname(__FILE__)."/".$_GET['file'],'a');


it was taking 4rever to open the file, so i thought it to be a folder/file permission problem.
That's why I wen to windows explorer and attempted to add permission to the files with no joy.
I'm logged in windows as the admin, so I dont understand why it would restrict me changing permissions in any folder even though its outside the user(admin) tree.

Thanks a lot for your attention.
Mike
MikeSpider
 
Posts: 6
Joined: 10. July 2012 16:53
Operating System: Windows 7 home edition

Re: Unable to share a folder in htdocs

Postby Altrea » 12. July 2012 15:21

MikeSpider wrote:I tried to change the
Code: Select all
$fp = fopen(dirname(__FILE__)."/".$_GET['file'],'r');

to
Code: Select all
$fp = fopen(dirname(__FILE__)."/".$_GET['file'],'a');


it was taking 4rever to open the file, so i thought it to be a folder/file permission problem.

mode 'a' is for writing only. If i understand correctly you want to read and write the file.
For this fopen has a mode 'a+'

Code: Select all
$fp = fopen(dirname(__FILE__)."/".$_GET['file'],'a+');


best wishes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: Unable to share a folder in htdocs

Postby MikeSpider » 12. July 2012 21:28

Thanks a lot Altrea, that did it!
Although It works but I realized now that it's not very effective, because when the file is edited and I press the save button,
It will always "save as" i wanted to be able to save exactly the same file. so I have to browse miles until I find the original file in the htdocs folder.
And when I open the file again it changes format to a web format, saying something like " this file has been modified by a web app".
I think it's the best it gets with a web app manipulating windows files ??

Anyways, i'm learning Visual Basic and trying to make a desktop equivalent although it's frustrating when you are good at something like "query searching" etc.. and have to re-learn it in another language and in other way. But it will get there.

Thanks so much for all the help!
I really appreciate,
Mike :)
MikeSpider
 
Posts: 6
Joined: 10. July 2012 16:53
Operating System: Windows 7 home edition

Re: Unable to share a folder in htdocs

Postby JonB » 13. July 2012 13:57

Mike -

I'm gratified that Altrea was able to clear things up on PHP file modes, I suspected that was part of the problem. The 'save as' issue is pure Windows OS.

Good Luck with your project and have fun.

8)
User avatar
JonB
AF Moderator
 
Posts: 3210
Joined: 12. April 2010 16:41
Location: Land of the Blazing Sun
Operating System: Windows XP/7 - Fedora 15 1.7.7


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 140 guests