Insert attachment information after upload

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Fakiro82
User
Posts: 108

Insert attachment information after upload

Post by Fakiro82 »

Hi,
I need to insert in table some attachment information (like attachment full path, extension, filename,etc...) after upload files.

They reported that I have to use the pathinfo function but I did not succeed. Can anyone explain how I can do it?

Thank you,
Andrea


sangnandar
User
Posts: 980

Post by sangnandar »

Ref:
www. w3schools. com / php/func_filesystem_pathinfo.asp

Row_Inserted()
$toInsert = pathinfo("/testweb/test.txt",PATHINFO_BASENAME); // line 1
ew_Execute("insert into ... values('".$toInsert."')"); // line 2

Line 1:

  • Replace /testweb/ with your upload directory.
  • Replace test.txt with $rsnew["myFile"] ; // myFile is your field upload, assuming varchar.
  • this line will output filename.ext, adjust pathinfo() options to get only extension.

Line 2:

  • Use Row Inserted() and ew_Execute() like the above, if you need insertion to another table.
  • For insertion into the same table it better use Row_Inserting()
    Row_Inserting()
    $filename = substr($rsnew["myFile"],0,strrpos($rsnew["myFile"],".")); // this line will output the string BEFORE the last dot of $rsnew["myFile"] string.
    $extension = substr($rsnew["myFile"],strrpos($rsnew["myFile"],".")+1); // this line will output the string AFTER the last dot of $rsnew["myFile"] string.
    $rsnew["filename"] = $filename;
    $rsnew["extension"] = $extension;

Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi sangnandar,
Thank you for your help.

Now, I insert this code in Row_Inserting:

// Row Inserting event
function Row_Inserting($rsold, &$rsnew) {

//INIZIO - Inserimento informazioni di upload file
$toInsert = pathinfo("/upload/$rsnew["Allegato"]",PATHINFO_BASENAME); // line 1
$filename = substr($rsnew["Allegato"],0,strrpos($rsnew["Allegato"],".")); // this line will output the string BEFORE the last dot of $rsnew["myFile"] string.
$extension = substr($rsnew["Allegato"],strrpos($rsnew["Allegato"],".")+1); // this line will output the string AFTER the last dot of $rsnew["myFile"] string.
$rsnew["des_NomeAllegato"] = $toInsert;
$rsnew["des_NomeAllegato"] = $filename;
$rsnew["des_EstensioneAllegato"] = $extension;
//FINE - Inserimento informazioni di upload file
// To cancel, set return value to FALSE
return TRUE;
}

but i receive this error:
Parse error: syntax error, unexpected '"', expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\xampp\htdocs\GestDoc\tbl_allegatiinfo.php on line 1319.

I think that this line is wrong:
$toInsert = pathinfo("/upload/$rsnew["Allegato"]",PATHINFO_BASENAME); // line 1.

How can i do to resolve it?

Thank you so much,
Andrea.


Fakiro82
User
Posts: 108

Post by Fakiro82 »

Hi,
now it's work.

Thank you so much,
Andrea.


Post Reply