I am using codeigniter and I am trying to send an email with an attachment, It is working well when i upload pdf but if i upload word file, i receive an empty email, although I have checked the uploading of word file is successful as well, all the uploaded files are in the given path. But there is nothing in email in MSword file case. Here is my code:
//My email function in controller
$attachment = $_FILES['file']['name'];
$this->email->attach('uploads/enquiry/'.$attachment);
You need to provide full path of the file.
so instead of
$this->email->attach('uploads/enquiry/'.$attachment);
try something like this
$this->email->attach(FCPATH.'/uploads/enquiry/'.$attachment);
Try it this way,
You will surely get answer :-
http://ellislab.com/codeigniter%20/user-guide/libraries/file_uploading.html
Related
I have successfully uploaded and downloaded files and downloaded files metadata
from OneDrive and Dropbox using Xamarin.Auth 1.5. I have done all of this for Google Drive except when
I upload a file I cannot name the file (shows as Untitled) and I cannot update
the file once it is uploaded.
Below is code for uploading a file (creating) initially:
Data for the file is in stream. Scope is https://www.googleapis.com/auth/drive.
URI uri = new Uri("https://www.googleapis.com/upload/drive/v3/files?uploadType=media");
OAuth2Request requestUpload = new OAuth2Request("POST", uri, null, (Account)authAccount);
requestUpload.AddMultipartData("body", stream, "application/json", dataFileName);
var responseUpload = await requestUpload.GetResponseAsync();
To update the file, I have tried adding the fileid to the url after files (e.g. files/fileid) and
I received System.Net.HttpStatusCode.NotFound and I know that the fileid is correct because I was
able to download the file using the same fileid. With the fileid, I also tried to use method PATCH
but I received a Xamarin.Auth error.
To rename the file, I have tried using two AddMultipartData, one for data and the other for
metadata (name) with correct formatting and all of the AddMultipartData metadata is added
inside the file with the body data. I tried adding both data and metadata in one AddMultipartData
with the same result as using two.
For both rename and update, I have tried all types of combinations, e.g. different uploadTypes, without
/upload, method PUT, IDictionary parameters, just to name a few.
Does anyone know how to do this? Thanks for any help or suggestions.
Xamarin.Auth has little to do with google drive APIs. It merely gets token for you.
All I can think of is that Xamarin.Auth intercepted some exception during PATCh and re-throw as Xamarin.Auth exception.
I suggest - issue on github. And ping me in community slack.
I am using ServiceNow Attachment API - POST /now/attachment/upload. This is working fine for all file types configured in Security properties. However it does not work when an attempt is made to upload a password protected office file, say Excel for example. I have tried uploading such file/s through their REST API Explorer as well as list item form with no luck.
When upload through SN form, the error received is "File mime type does not match the file content". SN form by always posts data as "application/octet-stream" however my upload script does set proper content-types and still fails. If content-type was the problem, it shouldn't have worked for unprotected file/s too.
Update
When I try to upload using REST API Explorer, it gives error for incorrect content-type. Same file without password works well. See screen shots below:
api/now/attachment/file
api/now/attachment/upload
You can upload password protected excel files to ServiceNow. Here is a snap shot where I uploaded a password protected attachment from REST API Explorer to an incident record. The content type really does not matter.
Setting MIME Type validation to false did the trick. This was acceptable in our case because we wanted to run PowerShell script that moved (uploaded) attachments from existing system to SN as part of data migration activity. It should ideally be turn on (true).
I am showing file names in a gridView. I have used a link for the file name. When user clicks the filename the file should be downloaded. For this I used ajax in javascript to send parameters to controller.
In my controller action I am using code
readfile( Yii::getPathOfAlias('webroot.order files').DIRECTORY_SEPARATOR.$order->user_id.DIRECTORY_SEPARATOR.$_GET['id'].DIRECTORY_SEPARATOR.$_GET['file']);
Yii::app()->end();
But the result is returned as a string in response.
Is there a way to download file from the returned string? I know file cant be downloaded from the string, i am just asking some way to download file using ajax.
I have created page for mail template and set buttons for preview template also.
I have set image path from my local machine like,
src="/projectname/app/webroot/img/logo.JPG"
and when i preview that template it displays logo.
when using that template when i send mail image is not displayed in email.
So can anyone please tell me what could be the issuee or i am missing something like mime types?
Thanks,
This won't work. The email is opened in a client, what the hack would a path like "/projectname/app/webroot/img/logo.JPG" mean to that client? What is the domain?
You can either add a domain to the SRC like src="http://example.com/projectname/app/webroot/img/logo.JPG". But this won't be displayed by default, because it is a security risk.
Imagine spammers including images like src="http://example.com/feedback?id=12345" to each email, where ID is identifying each e-mail address the mail is sent to. Each client downloading this image will acknowledge the receiving of this e-mail, letting the spammers know you are reading their spam. Most e-mail clients explicitly ask you whether images referred to in the mail should be downloaded or not.
An alternative solution is to include each e-mail as an attachment to the e-mail, then you can refer to it as an "inline" image. This does no requires external connection and is less of a security risk, mostly allowed by default in clients.
I've google up a component that supposedly supports also inlining, but you might find others as well:
http://bakery.cakephp.org/articles/CraZyLeGs/2006/12/18/swiftmailer-component-tutorial
Within emails, you must use your full path, not a relative path. To do this easily in CakePHP, use the: FULL_BASE_URL constant with the HTML Helper like this:
<?php
echo $this->Html->image(
FULL_BASE_URL . $photo['Photo']['path'].$photo['Photo']['filename']
);
?>
(obviously this could be done in one line, but I broke it down for ease of reading on StackOverflow)
That's probably because when you test on your local machine, that path is fine. But if you send an email to yourself (say gmail) your browser will probably look for the image somewhere like http://mail.google.com/gmail/projectname/app/webroot/img/logo.JPG and will not find your image there.
So you'll need to set your image source to something like http://localhost/projectname/app/webroot/img/logo.JPG.
The email client needs the absolute path to the image; use the HTML helper to attach the full base:
<?= $this->Html->image("logo.JPG", array('fullBase' => true)) ?>
Note that the /projectname/app/webroot/img/ is not required when using the HTML helper.
If you are using CakePHP v1.2 or 1.3 (yes they are deprecated - but hey someone might find this useful) you will need to add a Content-ID header to the image to be attached to the email so you can refer to it via the cid when using it inline in the message. Open the email controller of the cake installation and add this line in the __attachFiles() method:
$this->__message[] = 'Content-ID: <' . basename($file) . '>';
You can then add the image in your template like so:
The attachfile method of email class in v1.2 & 1.3 only accepts paths and does not have the added functionalities of later version hence the "hack"
I'm using the upload module to write the uploaded file to disk as soon as it arrives in nginx. In addition, I'd like to create 2 subrequests:
POST to a URL containing the uploaded file
POST to another URL without the uploaded file
The second request is easy to do because the upload module has already stripped out the upload. My problem is with the first request: How do I get the uploaded file back into the the subrequest.
A solution for my question has been committed to the echo module.
The module you linked to has the upload_set_form_field directive and a few special variables (listed in that directive), which you can use to pass the file details to the backend as a POST variables. The example given appears to put the upload back in the POST data. Can you adapt your backend script to make that work?