filesize() returns 0 bytes after file_put_contents

2,128 views
Skip to first unread message

David Vandemaele

unread,
Aug 13, 2013, 7:48:25 AM8/13/13
to sabredav...@googlegroups.com
Hello,

in the createFile function i store the file to a specific location, and afterwards, I save the information in the database for future reference.
The file is saved, but 'filesize()' returns 0 bytes. The variable $bytes contains also the value '0'. And of course, the mime_type utility function (using 'finfo_file()') returns 'application/x-empty').

This is the function:

public function createFile($name, $data = null) {

$bytes = file_put_contents($name, $data);
 
$file = new File();
$file->mimetype = Util::mime_type($name);
$file->name = $name;
$file->size = filesize($name);
$file->save();

}

How can I get the correct values?

Thanks in advance.

David

Evert Pot

unread,
Aug 13, 2013, 7:51:51 AM8/13/13
to sabredav...@googlegroups.com

Michael Kliewe

unread,
Aug 13, 2013, 8:09:28 AM8/13/13
to sabredav...@googlegroups.com

I'm not sure, $bytes should give you the bytes written. Can you check the file in the console or so, if it really has the content you expect? I would guess that you have other problems, maybe permissions or not enough space.
Please check with is_writable()
http://de2.php.net/manual/en/function.is-writable.php

The current PHP/Webserver user must have write access to that file/directory.

If the file is really there and has content (verify in command line or via FTP or so), then maybe it's the statcache.

Michael

David Vandemaele

unread,
Aug 13, 2013, 8:27:36 AM8/13/13
to sabredav...@googlegroups.com
Hi Michael,
The file is saved correctly. I can access it afterwards through DAV or command line.
The clearstatcache doesn't seems to help.  

David

David Vandemaele

unread,
Aug 13, 2013, 8:32:52 AM8/13/13
to sabredav...@googlegroups.com
If I upload the file through the browser plugin, then everything works fine.
The only difference I can come up with is that it's a POST action instead of a PUT.

David

Reply all
Reply to author
Forward
0 new messages