get Name of File Uploaded

Questionsget Name of File Uploaded
Senai asked 11 years ago

Hello Abu
I have been trying your file upload code, It is uploading successfully after I have set the $col["upload_dir"]="../Docs/Contracts". But now I want to record the filename to the database. So can you suggest for me how I can get the filename of the file uploaded in the 'on_after_insert' function.

Best regards

9 Answers
Abu Ghufran answered 11 years ago

File uploading is in beta stages, and will be released in upcoming version.
It's not functional now.

Abu Ghufran answered 11 years ago

Hello,

Code is available now. Check your email for help.

Regards

Navaneethan answered 9 years ago

Hi,
I am also facing the same problem that I am not able to get the uploaded file name.

please help!

Thanks in advance

Abu Ghufran answered 9 years ago

Hello,

Please refer demos/editing/file-upload.php sample.

If your upload file field was 'note', you will get uploaded file path in $data['params']['note'] in callback

$e["on_insert"] = array("add_invoice", null, true);
$g->set_events($e);

// callback for add
function add_invoice($data)
{
$upload_file_path = $data["params"]["note"];
}

Navaneethan answered 9 years ago

HI Abu,
I used this for column
$col = array();
$col["title"] = "NOTE"; // caption of column
$col["name"] = "note"; // grid column name, must be exactly same as returned
$col["search"] = true;
$col["editable"] = true;
$col["width"] = "10";
$col["edittype"] = "file"; // render as file
$col["upload_dir"] ="temp/"; // upload here
$col["align"] = "center";
$cols[] = $col;

$e = array();
$e["on_insert"] = array("add_expensereport", null, true);
$g->set_events($e);

function add_expensereport($data)
{
$id = $data["id"];
$amount_spent = $data["params"]["amount_spent"];
$category = $data["params"]["categoryname"];
$upload_file_path = $data["params"]["note"];
$date = $data["params"]["date"];
$expense_reason = $data["params"]["expense_reason"];
$currency = $data["params"]["currency"];

mysql_query("INSERT INTO expense_report (category_id,amount_spent,attachment,date,expense_reason,currency,modified_date)values('$category','$amount_spent','$attachment','$date','$expense_reason','$currency',now())") or die(mysql_error());
}

But note value is empty during insert as below:
INSERT INTO expense_report (category_id,amount_spent,note,date,expense_reason,currency,modified_date)values('1','1000','','2015-03-01','test','INR',now())

thanks,
Navaneethan

Navaneethan answered 9 years ago

sry note not attachment
mysql_query("INSERT INTO expense_report (category_id,amount_spent,note,date,expense_reason,currency,modified_date)values('$category','$amount_spent','$upload_file_path','$date','$expense_reason','$currency',now())") or die(mysql_error());
}

Abu Ghufran answered 9 years ago

Hello,

Currently it stores file name and the actual file contents can be read by file_get_contents function.
If you are using full version, demos/editing/file-upload.php contains working demo.

If using free / old version, please follow http://phpgrid.org/download -> buy

Navaneethan answered 8 years ago

Hi Abu,
How to Resize The Image Before Uploading in file-upload or any zoom in zoom out option available in fancybox for showing image because we didn't want to scroll down instead of that we reduce file size or zoom in option in that if u have idea for that.
Thanks,
P.Navaneethan

Abu Ghufran answered 8 years ago

Hello,

You can do such alteration after file upload and inside on_insert / on_update event handler.
Refer: http://www.phpgrid.org/docs/#Grid_Events

Your Answer

0 + 6 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?