This topic is locked
[SOLVED]

 Upload files to users folders

9/28/2011 6:57:32 AM
PHPRunner General questions
F
Francesco_5000 author

hi
i'm using this before record add/updated event:

// ok, va bene

//$values["nome_istituto"] viene usata come nome della directory

global $pageObject;

foreach( $pageObject->filesToMove as $key=>$val)

{

if($pageObject->filesToMove[$key]->sourceFilename==$_FILES["value_licenza_istituto_1"]["tmp_name"])
{

//crea la directory se non esiste

$dirname= "licenze_istituti/".$values["nome_istituto"];

if (is_dir($dirname)) {

} else {

mkdir("licenze_istituti/".$values["nome_istituto"], 0777);

}

$pageObject->filesToMove[$key]->destFilename =

$values["nome_istituto"]."/".$_FILES["value_licenza_istituto_1"]["name"];

}

}

$values["licenza_istituto"] = $_FILES["value_licenza_istituto_1"]["name"];
// ok, va bene

define("MAX_SIZE",1048576); // max 1 mb

$mysize=$_FILES["value_licenza_istituto_1"]["size"];
if($mysize > MAX_SIZE && MAX_SIZE > 0){

$values["licenza_istituto"]="";

$message = "<div class=message><<< Il file è troppo grande >>></div>";

return false;

}
// ok, va bene

$ext = explode(".", $values["licenza_istituto"]);

$ext = strtolower($ext[count($ext)-1]);
if ($ext <> "pdf")

{

$message = "<div class=message><<< Il file che stai cercando di inserire non è un pdf >>></div>";

return false;

}

return true;


to upload files to users folders. The upload works fine. But unfortunately:

  1. i can't delete the file when i update the record with a different pdf;
  2. i can't reach the file with the default link present in the list page;
  3. i can't add/edit records inline;
  4. after adding a record i can't see/edit the record with the link present in the message box (the value of the variable editid1 is empty).
    IMHO all these drawbacks are related to the fact that the pages generated with phprunner can't see the uploaded file in it's custom directory.
    Do you have any suggestions?

F
Francesco_5000 author 9/28/2011

here is the solution... in "before record add/updated event" i used this additional code:

// ok, va bene

$supp_istituto= str_replace(" ","",$values["nome_istituto"]);

$supp_istituto= str_replace("'","",$supp_istituto);
$indirizzo=$supp_istituto."/".$values["licenza_istituto"];

$values["licenza_istituto"]=$indirizzo;


In addiction to that i have disabled the inline add/edit, and to correct the drawback number 4) i used a redirection event.