Skip to content

Commit

Permalink
changed name of file upload setting; added documention for some parts…
Browse files Browse the repository at this point in the history
… of the 'form' functionality
  • Loading branch information
rob7hunter committed Nov 10, 2008
1 parent 1819cb2 commit 9221a85
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
6 changes: 3 additions & 3 deletions files.scm
Expand Up @@ -6,19 +6,19 @@

(provide save-uploaded-file-and-return-filename!)

(declare-setting *PATH_TO_FILEDATA* (build-path (current-directory) "uploaded-files"))
(declare-setting *PATH_TO_UPLOADED_FILES* (build-path (current-directory) "uploaded-files"))

(define (save-uploaded-file-and-return-filename! file-data)
(let* ((filename (fresh-filename-id (binding/string:file-filename file-data)))
(raw-file-bytes (binding/string:file-content file-data))
(fport (open-output-file (build-path (setting *PATH_TO_FILEDATA*) filename)
(fport (open-output-file (build-path (setting *PATH_TO_UPLOADED_FILES*) filename)
#:exists 'error)))
(write-bytes raw-file-bytes fport)
(close-output-port fport)
filename))

(define (fresh-filename-id filename #:id-length (id-length 5))
(let ((try (string-append (random-key-string id-length) "-" filename)))
(if (file-exists? (build-path (setting *PATH_TO_FILEDATA*) try))
(if (file-exists? (build-path (setting *PATH_TO_UPLOADED_FILES*) try))
(fresh-filename-id filename #:id-length id-length)
try)))

0 comments on commit 9221a85

Please sign in to comment.