Results 1 to 8 of 8

Thread: problem uploading files

  1. #1
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    403

    Wink problem uploading files

    Hello friends, I need your help
    I am trying to upload documents from sugar to my server
    I created my custom code in detail view of my module (the form in html that calls the upload.php file), because I want to upload my documents from detail view of the module.
    So I created the upload.php in order to upload the document...

    PHP Code:
    <?php
     $numaviso 
    $_POST["num_aviso"];
     
    $aux $numaviso;
     
      
    //recorro la cadena aux
        
    for($i=strlen($aux);$i>0;$i--){ 
            if(
    $aux{$i} != '_'){
                
    $aux{$i} = "";
            }else{
                
    $aux{$i} = "";
                if(
    $aux{$i-1} == '.'){
                    
    $aux{$i-1} = "";
                }
                
    $i=0;
            }        
        } 
    [
    B$uploaddir "/xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/{$aux}/"; [/B]
     
    $uploadfile $uploaddir basename($_FILES['archivo']['name']);
     
    $error $_FILES['archivo']['error'];
     
    $subido false;
     if(isset(
    $_POST['boton']) && $error==UPLOAD_ERR_OK){ 
       
    $subido copy($_FILES['archivo']['tmp_name'], $uploadfile); 
      } 
       if(
    $subido) { 
        echo 
    "El archivo se ha subido"
       } else {
        echo 
    "Se ha producido un error: ".$error;
      }
    ?>
    My problem is in $uploaddir , because if I write the path manually, then the document upload to my server correctly, for example:
    $uploaddir = "/xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/mydir/"

    but I need to upload the document to differents paths on depending of my needs, so I must write the $uploaddir with variables, but then when I try to upload a document appears this message:

    [function.copy]: failed to open stream: Permission denied in C:\xampp\htdocs\sugarcrm\modules\Biomasas\metadata \subir.php on line 22
    Se ha producido un error: 0

    Someone can help me?
    Thanks
    Daniel

    It is not a problem of permits, because I have checked it already.

  2. #2
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: problem uploading files

    This is due a file permission issue at /xampp/htdocs/sugarcrm/docs/.
    You need to make sure apache user has, recursively, write/read access to such folder.

    Regards
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  3. #3
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    403

    Default Re: problem uploading files

    Hello andopes thanks so much for your answer
    I think this is not my problem (I'm not sure) because if I write a constant upload path in order to upload my document, then all goes correctly.

    But my problem is that I need to write the upload path on depending of my variable that I receive of the html form, because in this html form I have a dropdown list in order to select the directory where the user want to upload the file.

    I hope you urderstand me andopes,
    Daniel

  4. #4
    andopes's Avatar
    andopes is offline A Sugar Hero | Help Forum Moderator
    Join Date
    Jul 2006
    Location
    São Paulo - Brazil
    Posts
    8,335

    Default Re: problem uploading files

    I do understand that.
    By choosing a static folder there is no variable, and you are sure all files will be saved in the same place.
    But you need to make sure all customer based folders exist and they are readable/writable by the apache user.
    Let us know the output of "ls -lh /xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/"
    Let us know an example of a client folder. Probably such folder doesn't exist or is not allowed for the apache user.

    Cheers
    André Lopes
    DevToolKit / Project of the Month - June 2009
    Lampada Global Services- Open Source Solutions
    Avenida Ipiranga, 318
    Bloco B - CJ 1602
    São Paulo, SP 01046-010
    Brazil
    Office: +55 11 3237-3110
    Mobile: +55 11 7636-5859
    e-mail: andre@lampadaglobal.com

    Lampada Global delivers offshore software development and support services to customers around the world.
    Lampada is proud to be a SugarCRM Gold Partner, revolutionizing Customer Relationship Management.

    I DO NOT answer questions through PM and Email. If you need some help post your question into SugarForum.

  5. #5
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    403

    Default Re: problem uploading files

    In the code php attached, I pick up the parameter: 'numaviso' that come of the html form. I need it to complete the upload path.

    I implement the loop for, because I need delete the characters which are after the caracter '_'

    In this example, $numaviso has the value: 0001_DANIEL GARCIA_B1
    and I need only: 0001_DANIEL GARCIA (because this is the directory where I need upload the document), so I create another variable called 'aux', and with the loop for, I assign the value: 0001_DANIEL GARCIA,to the variable 'aux'...... but when I concatenate the variable 'aux' to the path, this not goes good.

    This is my problem

  6. #6
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    403

    Default Re: problem uploading files

    Quote Originally Posted by andopes View Post
    I do understand that.
    By choosing a static folder there is no variable, and you are sure all files will be saved in the same place.
    But you need to make sure all customer based folders exist and they are readable/writable by the apache user.
    Let us know the output of "ls -lh /xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/"
    Let us know an example of a client folder. Probably such folder doesn't exist or is not allowed for the apache user.

    Cheers
    Yes, the folders of customers already exist, because the first step is to create the client, and in the moment of creation of one client, I implemented the creation of the folders of this client. And, when I create the folder, I assign permissions 0777 to the folder

    A example:

    1.First step: Creation of the client named: Daniel Garcia -> Automatic creation of the folder /xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/0001_DANIEL GARCIA (or 0002, or 0003... on depending of the counter)

    2.Second step:For this client (all clients generally), I can create differents jobs (biomass, solar, thermal..) -> Automatic creation of the folder
    2.1 /xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/0001_DANIEL GARCIA/0001_DANIEL GARCIA_B1 -> if I create biomass
    2.2 /xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/0001_DANIEL GARCIA/0001_DANIEL GARCIA_T1 -> if I create thermal

    3.Third step: I create one job (by subpanel of the detail view of DANIEL GARCIA) for this client. In this example I create biomass ->Automatic creation of the folder
    /xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/0001_DANIEL GARCIA/0001_DANIEL GARCIA_B1

    4.Fourth step: Uploading documents in detail view of the job biomass of the client DANIEL GARCIA. So in detail view of the job biomass, I send the variable with the value: 0001_DANIEL GARCIA_B1 as parameter from the html form to the upload.php file. I need upload the document in this absolute path:
    /xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/0001_DANIEL GARCIA/0001_DANIEL GARCIA_B1

    So with loop for I delete _B1 in order to access firstly to /0001_DANIEL GARCIA folder, but then appear the error of permissions.....but if I write manually
    $uploaddir="/xampp/htdocs/sugarcrm/docs/DOCUM_CLIENTES/0001_DANIEL GARCIA/0001_DANIEL GARCIA_B1";
    the uploading procedure goes good, but I can not do in this way because the upload path will change on depending of the job of the client...
    Last edited by garciasanchezdaniel; 2011-09-12 at 03:49 PM.

  7. #7
    garciasanchezdaniel's Avatar
    garciasanchezdaniel is offline Sugar Community Member
    Join Date
    Aug 2011
    Location
    Spain
    Posts
    403

    Default Re: problem uploading files

    I solved it!!!
    It was mine mistake, because I didn't realise that I could create other parameter in html form in order to send to upload.php, this paramaterer contain exactly the value that I need to concatenate to upload path
    So, I don't need that loop for, that was the problem, it seems that I didn't make well
    Now, all is right
    thanks andopes
    Daniel

  8. #8
    montolla's Avatar
    montolla is offline Sugar Community Member
    Join Date
    Sep 2011
    Location
    Medellin, Colombia
    Posts
    49

    Default Re: problem uploading files

    Quote Originally Posted by andopes View Post
    This is due a file permission issue at /xampp/htdocs/sugarcrm/docs/.
    You need to make sure apache user has, recursively, write/read access to such folder.

    Regards
    Hello


    Try

    chmod 777 -R /xampp/htdocs/sugarcrm/ or

    or
    chgrp -R www-data /xampp/htdocs/sugarcrm/

    Thans

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Uploading Files when Adding/Editing Record
    By madcoder1988 in forum Developer Help
    Replies: 3
    Last Post: 2011-06-06, 01:41 PM
  2. Uploading Project Files
    By brianhildebrandt in forum Help
    Replies: 1
    Last Post: 2010-11-04, 07:55 PM
  3. Replies: 0
    Last Post: 2009-06-05, 03:25 PM
  4. Uploading files with wrong permissions
    By rafael.menezes in forum Help
    Replies: 0
    Last Post: 2006-10-23, 02:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •