Skip to content

Commit

Permalink
Add a parameter for the function setFileToSend, showing up in the Bro…
Browse files Browse the repository at this point in the history
…wser instead of to download.
  • Loading branch information
dreamsxin committed Jul 17, 2013
1 parent 7da72c1 commit 7372cd6
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 18 deletions.
10 changes: 9 additions & 1 deletion build/32bits/phalcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -15105,7 +15105,7 @@ static PHP_METHOD(Phalcon_Http_Response, send){

static PHP_METHOD(Phalcon_Http_Response, setFileToSend){

zval *file_path, *attachment_name = NULL, *base_path = NULL;
zval *file_path, *attachment_name = NULL, *attachment, *base_path = NULL;
zval *headers, *content_description, *content_disposition;
zval *content_transfer;

Expand All @@ -15116,6 +15116,11 @@ static PHP_METHOD(Phalcon_Http_Response, setFileToSend){
if (!attachment_name) {
PHALCON_INIT_VAR(attachment_name);
}

if (!attachment) {
PHALCON_INIT_VAR(attachment);
ZVAL_BOOL(attachment, 1);
}

if (Z_TYPE_P(attachment_name) != IS_STRING) {
PHALCON_INIT_VAR(base_path);
Expand All @@ -15126,6 +15131,8 @@ static PHP_METHOD(Phalcon_Http_Response, setFileToSend){

PHALCON_INIT_VAR(headers);
phalcon_call_method_key(headers, this_ptr, "getheaders", 927788161UL);

if (zend_is_true(attachment)) {

PHALCON_INIT_VAR(content_description);
ZVAL_STRING(content_description, "Content-Description: File Transfer", 1);
Expand All @@ -15138,6 +15145,7 @@ static PHP_METHOD(Phalcon_Http_Response, setFileToSend){
PHALCON_INIT_VAR(content_transfer);
ZVAL_STRING(content_transfer, "Content-Transfer-Encoding: binary", 1);
phalcon_call_method_p1_key(NULL, headers, "setraw", content_transfer, 2352298299UL);
}
phalcon_update_property_this_quick(this_ptr, SL("_file"), file_path, 3974776868UL TSRMLS_CC);

RETURN_THIS();
Expand Down
1 change: 1 addition & 0 deletions build/32bits/phalcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_http_responseinterface_setfiletosend, 0, 0, 1)
ZEND_ARG_INFO(0, filePath)
ZEND_ARG_INFO(0, attachmentName)
ZEND_ARG_INFO(0, attachmentName)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_http_responseinterface_method_entry){
Expand Down
15 changes: 12 additions & 3 deletions build/64bits/phalcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -15105,17 +15105,23 @@ static PHP_METHOD(Phalcon_Http_Response, send){

static PHP_METHOD(Phalcon_Http_Response, setFileToSend){

zval *file_path, *attachment_name = NULL, *base_path = NULL;
zval *file_path, *attachment_name = NULL, *attachment = NULL, *base_path = NULL;
zval *headers, *content_description, *content_disposition;
zval *content_transfer;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 1, 1, &file_path, &attachment_name);
phalcon_fetch_params(1, 1, 2, &file_path, &attachment_name, &attachment);

if (!attachment_name) {
PHALCON_INIT_VAR(attachment_name);
}

if (!attachment) {
PHALCON_INIT_VAR(attachment);
ZVAL_BOOL(attachment, 1);
}


if (Z_TYPE_P(attachment_name) != IS_STRING) {
PHALCON_INIT_VAR(base_path);
Expand All @@ -15126,7 +15132,8 @@ static PHP_METHOD(Phalcon_Http_Response, setFileToSend){

PHALCON_INIT_VAR(headers);
phalcon_call_method_key(headers, this_ptr, "getheaders", 13875266023911648385UL);


if (zend_is_true(attachment)) {
PHALCON_INIT_VAR(content_description);
ZVAL_STRING(content_description, "Content-Description: File Transfer", 1);
phalcon_call_method_p1_key(NULL, headers, "setraw", content_description, 229482454923579UL);
Expand All @@ -15138,6 +15145,8 @@ static PHP_METHOD(Phalcon_Http_Response, setFileToSend){
PHALCON_INIT_VAR(content_transfer);
ZVAL_STRING(content_transfer, "Content-Transfer-Encoding: binary", 1);
phalcon_call_method_p1_key(NULL, headers, "setraw", content_transfer, 229482454923579UL);

}
phalcon_update_property_this_quick(this_ptr, SL("_file"), file_path, 6953231861796UL TSRMLS_CC);

RETURN_THIS();
Expand Down
2 changes: 2 additions & 0 deletions build/64bits/phalcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_http_responseinterface_setfiletosend, 0, 0, 1)
ZEND_ARG_INFO(0, filePath)
ZEND_ARG_INFO(0, attachmentName)
ZEND_ARG_INFO(0, attachment)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_http_responseinterface_method_entry){
Expand Down Expand Up @@ -10852,6 +10853,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_http_response_setfiletosend, 0, 0, 1)
ZEND_ARG_INFO(0, filePath)
ZEND_ARG_INFO(0, attachmentName)
ZEND_ARG_INFO(0, attachment)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_http_response_method_entry){
Expand Down
13 changes: 10 additions & 3 deletions build/safe/phalcon.c
Original file line number Diff line number Diff line change
Expand Up @@ -15105,17 +15105,23 @@ static PHP_METHOD(Phalcon_Http_Response, send){

static PHP_METHOD(Phalcon_Http_Response, setFileToSend){

zval *file_path, *attachment_name = NULL, *base_path = NULL;
zval *file_path, *attachment_name = NULL, *attachment, *base_path = NULL;
zval *headers, *content_description, *content_disposition;
zval *content_transfer;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 1, 1, &file_path, &attachment_name);
phalcon_fetch_params(1, 1, 2, &file_path, &attachment_name, &attachment);

if (!attachment_name) {
PHALCON_INIT_VAR(attachment_name);
}

if (!attachment) {
PHALCON_INIT_VAR(attachment);
ZVAL_BOOL(attachment, 1);
}


if (Z_TYPE_P(attachment_name) != IS_STRING) {
PHALCON_INIT_VAR(base_path);
Expand All @@ -15126,7 +15132,7 @@ static PHP_METHOD(Phalcon_Http_Response, setFileToSend){

PHALCON_INIT_VAR(headers);
phalcon_call_method(headers, this_ptr, "getheaders");

if (zend_is_true(attachment)) {
PHALCON_INIT_VAR(content_description);
ZVAL_STRING(content_description, "Content-Description: File Transfer", 1);
phalcon_call_method_p1_noret(headers, "setraw", content_description);
Expand All @@ -15138,6 +15144,7 @@ static PHP_METHOD(Phalcon_Http_Response, setFileToSend){
PHALCON_INIT_VAR(content_transfer);
ZVAL_STRING(content_transfer, "Content-Transfer-Encoding: binary", 1);
phalcon_call_method_p1_noret(headers, "setraw", content_transfer);
}
phalcon_update_property_this(this_ptr, SL("_file"), file_path TSRMLS_CC);

RETURN_THIS();
Expand Down
1 change: 1 addition & 0 deletions build/safe/phalcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2263,6 +2263,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_http_responseinterface_setfiletosend, 0, 0, 1)
ZEND_ARG_INFO(0, filePath)
ZEND_ARG_INFO(0, attachmentName)
ZEND_ARG_INFO(0, attachment)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_http_responseinterface_method_entry){
Expand Down
29 changes: 18 additions & 11 deletions ext/http/response.c
Original file line number Diff line number Diff line change
Expand Up @@ -778,17 +778,22 @@ PHP_METHOD(Phalcon_Http_Response, send){
*/
PHP_METHOD(Phalcon_Http_Response, setFileToSend){

zval *file_path, *attachment_name = NULL, *base_path = NULL;
zval *file_path, *attachment_name = NULL, *attachment = NULL, *base_path = NULL;
zval *headers, *content_description, *content_disposition;
zval *content_transfer;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 1, 1, &file_path, &attachment_name);
phalcon_fetch_params(1, 1, 2, &file_path, &attachment_name, &attachment);

if (!attachment_name) {
PHALCON_INIT_VAR(attachment_name);
}

if (!attachment) {
PHALCON_INIT_VAR(attachment);
ZVAL_BOOL(attachment, 1);
}

if (Z_TYPE_P(attachment_name) != IS_STRING) {
PHALCON_INIT_VAR(base_path);
Expand All @@ -800,17 +805,19 @@ PHP_METHOD(Phalcon_Http_Response, setFileToSend){
PHALCON_INIT_VAR(headers);
phalcon_call_method(headers, this_ptr, "getheaders");

PHALCON_INIT_VAR(content_description);
ZVAL_STRING(content_description, "Content-Description: File Transfer", 1);
phalcon_call_method_p1_noret(headers, "setraw", content_description);
if (zend_is_true(attachment)) {
PHALCON_INIT_VAR(content_description);
ZVAL_STRING(content_description, "Content-Description: File Transfer", 1);
phalcon_call_method_p1_noret(headers, "setraw", content_description);

PHALCON_INIT_VAR(content_disposition);
PHALCON_CONCAT_SV(content_disposition, "Content-Disposition: attachment; filename=", base_path);
phalcon_call_method_p1_noret(headers, "setraw", content_disposition);
PHALCON_INIT_VAR(content_disposition);
PHALCON_CONCAT_SV(content_disposition, "Content-Disposition: attachment; filename=", base_path);
phalcon_call_method_p1_noret(headers, "setraw", content_disposition);

PHALCON_INIT_VAR(content_transfer);
ZVAL_STRING(content_transfer, "Content-Transfer-Encoding: binary", 1);
phalcon_call_method_p1_noret(headers, "setraw", content_transfer);
PHALCON_INIT_VAR(content_transfer);
ZVAL_STRING(content_transfer, "Content-Transfer-Encoding: binary", 1);
phalcon_call_method_p1_noret(headers, "setraw", content_transfer);
}
phalcon_update_property_this(this_ptr, SL("_file"), file_path TSRMLS_CC);

RETURN_THIS();
Expand Down
1 change: 1 addition & 0 deletions ext/http/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_http_response_setfiletosend, 0, 0, 1)
ZEND_ARG_INFO(0, filePath)
ZEND_ARG_INFO(0, attachmentName)
ZEND_ARG_INFO(0, attachment)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_http_response_method_entry){
Expand Down

0 comments on commit 7372cd6

Please sign in to comment.