Skip to content
This repository has been archived by the owner on Nov 17, 2021. It is now read-only.

problem with FileByteStream.php #298

Closed
pankov-anton opened this issue Feb 27, 2013 · 11 comments
Closed

problem with FileByteStream.php #298

pankov-anton opened this issue Feb 27, 2013 · 11 comments

Comments

@pankov-anton
Copy link

sviftmailer used in AVE.CMS 3.0RC2 v1.3
When submitting a form, which is present in the field, attach a file, an error:
Warning: fopen(тестовый_файл.docx) [function.fopen]: failed to open stream: No such file or directory in Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\ByteStream\FileByteStream.php on line 125

Fatal error: Uncaught exception 'Swift_IoException' with message 'Unable to open file for reading [тестовый_файл.docx]' in Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\ByteStream\FileByteStream.php:126 Stack trace: #0 Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\ByteStream\FileByteStream.php(75): Swift_ByteStream_FileByteStream->_getReadHandle() #1 Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\Mime\SimpleMimeEntity.php(647): Swift_ByteStream_FileByteStream->read(8192) #2 Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\Mime\SimpleMimeEntity.php(331): Swift_Mime_SimpleMimeEntity->_readStream(Object(Swift_ByteStream_FileByteStream)) #3 Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\Mime\SimpleMimeEntity.php(441): Swift_Mime_SimpleMimeEntity->getBody() #4 Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\Mime\SimpleMimeEntity.php(454): Swift_Mime_SimpleMimeEntity->toString() #5 Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\Mime\SimpleMessage.php(537): Swift_Mime_S in Z:\home\ave-okna.ru\www\lib\SwiftMailer\classes\Swift\ByteStream\FileByteStream.php on line 126

Replacement
if (!$this->_reader = fopen($this->_path, 'rb')) {
to
if (empty($this->_path))
return null;
if (!$this->_reader = fopen($this->_path, 'rb')) {
does not work

How to get out of this situation?The latest version of the same problem.

@ammont
Copy link

ammont commented Jan 21, 2014

+1

@sstok
Copy link
Contributor

sstok commented Jan 21, 2014

Try using the full path, using only the filename FileByteStream can not determine the directory the file is in.

@ammont
Copy link

ammont commented Jan 22, 2014

I have the same problem with dynamic attachment:

$debug_data = 'Exception: ' . $e_message . PHP_EOL;
$debug_data .= $file . ': ' . $line . PHP_EOL;
$debug_data .= $trace;

$attach = Swift_Attachment::newInstance($debug_data, 'debug.txt', 'text/plain');

$message->attach($attach);

error:

Error in exception handler: fopen(Content-Type: text/plain; name=debug.txt Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=debug.txt 1ay9wdWJsaWMvaW5kZXgucGhwKDQ5KTog SWxsdW1pbmF0ZVxGb3VuZGF0aW9uXEFwcGxpY2F0aW9uLT5ydW4oKQojMTMge21haW59): failed to open stream: No such file or directory in /vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php:138

@sstok
Copy link
Contributor

sstok commented Jan 22, 2014

Thats strange, its correct according to the documentation.
http://swiftmailer.org/docs/messages.html#attaching-dynamic-content

And I can't find any strange things in the source, @ammont can you make a small script to reproduce this?
It will make debugging this issue allot easier.

@xdecock
Copy link
Member

xdecock commented Jan 22, 2014

This seems to be an fopen on the mime entity converted to string, it's
quite strange

On Wed, Jan 22, 2014 at 10:02 AM, Sebastiaan Stok
notifications@github.comwrote:

Thats strange, its correct according to the documentation.
http://swiftmailer.org/docs/messages.html#attaching-dynamic-content

And I can't find any strange things in the source, @ammonthttps://github.com/ammontcan you make a small script to reproduce this?
It will make debugging this issue allot easier.


Reply to this email directly or view it on GitHubhttps://github.com//issues/298#issuecomment-33003565
.

Xavier De Cock
GPG Fingerprint: 93CA EE3F 9F57 5BE1 AE4A 794D 3C74 CA9E E7A5 0C1B
GPG Id: 0xE7A50C1B

@jbrooksuk
Copy link

I'm experiencing this issue too with 5.2.1

I've got a PDF string generated by mPDF and I'm doing this:

$Attachment = Swift_Attachment::newInstance($PDFContent, $fileName, 'application/pdf');

But I'm getting a fopen error:

fopen(Content-Type: application/pdf; name=121103-201407151603.pdf Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=121103-201407151603.pdf JVBERi0xLjQKJeLjz9MKJVBERi0xLjQKJeLjz9MKJVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9U eXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL01lZGlhQm94IFswIDAgNTk1LjI4MCA4NDEuODkwXQov VHJpbUJveCBbMC4wMDAgMC4wMDAgNTk1LjI4MCA4NDEuODkwXQovUmVzb3VyY2VzIDIgMCBSCi9H cm91cCA8PCAvVHlwZSAvR3JvdXAgL1MgL1RyYW5zcGFyZW5jeSAvQ1MgL0RldmljZVJHQiA+PiAK L0NvbnRlbnRzIDQgMCBSPj4KZW5kb2JqCjQgMCBvYmoKPDwvRmlsdGVyIC9GbGF0ZURlY29kZSAv TGVuZ3RoIDMxNTM+PgpzdHJlYW0KYrM3JtovtJOy33W+ipWFRWyc7uoVBdyLUOQjyC8QNrzOVMXD 5a87qaC7gmUa9LcyiFRKxhThZOkbch8V8waOH6/xG04AZZBqnnMPP3XG4ekbljfLoTLCUrcpysPk sAiE+0EBakfjf0eQhmo3vCFqVyGGB3SdcSR/Ow0qeyucvElVYWuMvUbHVRJlA5nE5071tznk0UBr iqOLKcrLfRrMvf+Z463/iT4cwWAPdbkpxtaULglDVNPNyIx3eqnwM9Vgwg6Q/fslMEZD4FszmGHq 9MyGgdtoPqqThqgTHeM1kq//DECRxo7fVMkiN+cgLmgkMhPQyTC/4qHost9VSKmKuNVTFrnebkm6 q3YzH5GP2rM3eXYKdBlogq/5aCdvkfiIVLybaBzUsJDlxQNTRKXL4iVxOmU9LboR6hxGp0rwU9GK 
.....
 failed to open stream: Invalid argument (View: /Users/james.brooks/Sites/bloot/app/views/quotes/index.blade.php)

@jbrooksuk
Copy link

@fabpot and @d11wtq any ideas? I don't want to keep generating PDF's on disk.

@xdecock
Copy link
Member

xdecock commented Jul 15, 2014

:| it's not the good syntax for b64 wrapper (or try the php://temp / memory
wrapper)

http://php.net//manual/en/wrappers.php.php

On Tue, Jul 15, 2014 at 5:13 PM, James Brooks notifications@github.com
wrote:

@fabpot https://github.com/fabpot and @d11wtq
https://github.com/d11wtq any ideas? I don't want to keep generating
PDF's on disk.


Reply to this email directly or view it on GitHub
#298 (comment)
.

Xavier De Cock
GPG Fingerprint: 93CA EE3F 9F57 5BE1 AE4A 794D 3C74 CA9E E7A5 0C1B
GPG Id: 0xE7A50C1B

@jbrooksuk
Copy link

@xdecock wouldn't that have to be implemented in SwiftMailer itself? I've tried sending it handles etc.

@jbrooksuk
Copy link

My bad. Laravel has a method called attach and I just found.... attachData.

@xdecock
Copy link
Member

xdecock commented Jul 15, 2014

eheh : http://php.net/manual/en/wrappers.data.php

this is the good system

otherwise you can create "raw" mime part

On Tue, Jul 15, 2014 at 5:16 PM, James Brooks notifications@github.com
wrote:

@xdecock https://github.com/xdecock wouldn't that have to be
implemented in SwiftMailer itself? I've tried sending it handles etc.


Reply to this email directly or view it on GitHub
#298 (comment)
.

Xavier De Cock
GPG Fingerprint: 93CA EE3F 9F57 5BE1 AE4A 794D 3C74 CA9E E7A5 0C1B
GPG Id: 0xE7A50C1B

@fabpot fabpot closed this as completed Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants