1

Has anyone had an instance like this?

I have a Matrix field which contains a Safecracker File upload field.

When I upload a file via this (in the regular control panel) the file uploads but the name has the directory prepended to it.

Say the file was called "my_document.pdf" and was uploaded to a directory named "documents" would be called "documentsmy_document.pdf".

EDIT: I have actually "fixed" this now but I don't know if my fix will cause problems further down the line.

Looking at ft.safecracker_file.php I figured that save method was to blame. Towards the end there is a ternary conditional that prefixes the upload directory name to the file. I've changed that line so it doesn't.

Changing: $output = ($data && isset($this->settings['safecracker_upload_dir']) && $data !== 'NULL') ? '{filedir_'.$this->settings['safecracker_upload_dir'].'}'.$data : '';

To: $output = ($data && isset($this->settings['safecracker_upload_dir']) && $data !== 'NULL') ? $data : '';

Has 'solved' the issue for me but I'm unsure as to whether this was an intentional thing to avoid clashes of filenames that are in different directories - I can't really see how that could happen though. It all seems a bit odd.

1

I have actually "fixed" this now but I don't yet know if my fix will cause any problems further down the line.

Looking at ft.safecracker_file.php I figured that save method was to blame. Towards the end there is a ternary conditional that prefixes the upload directory name to the file. I've changed that line so it doesn't.

Changing:

$output = ($data && isset($this->settings['safecracker_upload_dir']) && $data !== 'NULL') ? '{filedir_'.$this->settings['safecracker_upload_dir'].'}'.$data : '';

To:

$output = ($data && isset($this->settings['safecracker_upload_dir']) && $data !== 'NULL') ? $data : '';

This has 'solved' the issue for me but I'm unsure as to whether this was an intentional thing to avoid clashes of filenames that are in different directories - I can't really see how that could happen though. It all seems a bit odd.

UPDATE: I've seen some weirdness with some Safecracker fields not returning any data (although passing a conditional check to see if they're populated). This could well be related to my hack - although again I am not sure why. The data in these fields was existing prior to my hack and they were working afterwards but suddenly stopped working.

Changing the fieldtype to a regular file field and back to a Safecracker file field seems to have sorted it so I am not sure what happened.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.