Ticket #491 (closed Feature Request: wontfix)

Opened 8 months ago

Last modified 8 months ago

Forge_Upload feature request w/ code

Reported by: ixmatus Owned by: Shadowhand
Priority: minor Milestone: 2.2
Component: Modules:Forge Version: SVN HEAD
Keywords: forge, upload, feature request, code Cc:

Description

I needed to upload a file and rename it to a static filename, such as 'header_image.jpg'. I also needed that file to be overwritten with a newly uploaded and renamed file by the same name.

To give a file a static name, you can simply do this:

$form->upload('file', 'news_image.jpg')->rules('required|size[1000KB]|allow[jpg]');

the second argument of 'upload' (where you can set a boolean True, False, or Null) can also be set as the desired static image name. Hope this makes sense, if not, ask and I will try to clarify more.

Index: Form_Upload.php
===================================================================
--- Form_Upload.php	(revision 2284)
+++ Form_Upload.php	(working copy)
@@ -100,7 +100,14 @@
 				{
 					// Prefix the file so that the filename is unique
 					$filepath = $this->directory.'uploadfile-'.uniqid(time()).'-'.$this->upload['name'];
+				} elseif (is_string($this->filename)) {
+					$filepath = $this->directory.$this->filename;
 				}
+			} elseif(!file_exists($filepath)) {
+				if (is_string($this->filename))
+				{
+					$filepath = $this->directory.$this->filename;
+				}
 			}

Change History

Changed 8 months ago by zombor

  • status changed from new to closed
  • resolution set to wontfix
Note: See TracTickets for help on using tickets.