You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Leaf Docs Show Incorrect Error Handling for Files #139
However, in Leaf v. 4.4 request()->upload() does file relocation with \Leaf\FS\File::upload() which logs errors to its own static::errorsArray. This errors array is not merged by request()->errors(). The code in \Leaf\Http::errors() shows:
public static function errors()
{
return array_merge(
static::$errors,
static::$validator ? static::$validator->errors() : [],
class_exists('\Leaf\Auth') ? static::auth()->errors() : []
);
}
This change fixes the issue for me:
public static function errors()
{
return array_merge(
static::$errors,
static::$validator ? static::$validator->errors() : [],
class_exists('\Leaf\Auth') ? static::auth()->errors() : [],
\Leaf\FS\File::errors() // merges File system errors to handle errors from upload.
);
}
I'm having students merge the two errors arrays manually in their code like this:
$uploadOk = request()->upload(/*details, yadda*/);
if (!$uploadOk)
{
$errors = array_merge($errors, request()->errors(), \Leaf\FS\File::errors()); // I'm having them add their own errors in the Controller as well for feedback in the View
It would be nice if either they didn't have to check the filesystem when they didn't appear to call it, or if the docs reflected the actual code. My test code from last January shows that I was doing the merge then, but I don't recall noticing it at the time. Possibly the documentation was incorrectly updated since then?
Does not include the name option which is very helpful, does not explain how name and rename relate, and includes recursive which is not used in the \Leaf\FS\File::upload() code. Instead, mkdir is simply sent true as the recursive argument. ARGH!
if (!$destinationIsBucket) {
$destinationPath = new Path($destination);
$destination = $destinationPath->normalize();
if (!Directory::exists($destination)) {
mkdir($destination, $options['mode'], true); // true instead of $options['recursive']! Why?
}
} else {
$file = fopen($temp, 'r+');
}
Activity
emajekral-collab commentedon Jun 23, 2026
While on the subject of that page, the sample upload request:
Does not include the
nameoption which is very helpful, does not explain hownameand renamerelate, and includesrecursivewhich is not used in the \Leaf\FS\File::upload() code. Instead,mkdiris simply senttrueas the recursive argument. ARGH!