Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a parameter for the function setFileToSend, showing up in the Browser instead of to download. #853

Closed
dreamsxin opened this issue Jul 17, 2013 · 3 comments

Comments

@dreamsxin
Copy link
Contributor

ex:

$this->response->setHeader('Cache-Control', 'max-age=3600');
$this->response->setContentType('image/jpeg');
$this->response->setFileToSend($filename, $this->user->id.'_avatar.jpg', NULL, FALSE);
$this->response->send();
@dreamsxin
Copy link
Contributor Author

$this->response->setHeader('Cache-Control', 'max-age=3600');
$this->response->setContentType('image/jpeg');
$this->response->setFileToSend($filename, NULL, FALSE);
$this->response->send();

dreamsxin@7372cd6

ext/http/response.c:

PHP_METHOD(Phalcon_Http_Response, setFileToSend){

        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, &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);
                phalcon_call_func_p1(base_path, "basename", file_path);
        } else {
                PHALCON_CPY_WRT(base_path, attachment_name);
        }

        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);

                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_update_property_this(this_ptr, SL("_file"), file_path TSRMLS_CC);

        RETURN_THIS();
}

@ghost
Copy link

ghost commented Jul 17, 2013

Well,

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

         if (zend_is_true(attachment)) {
+                PHALCON_INIT_VAR(headers);
+                phalcon_call_method(headers, this_ptr, "getheaders");

@dreamsxin
Copy link
Contributor Author

thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant