PHP Script Forums » PHP Classes Support Forum » Easy Upload class Support forum

easy upload multi file rename

(5 posts)
Please support us by buying these products:

  1. cstorey

    cstorey
    Member

    Hi Olaf,

    Thanks for a great class! I've used it successfully for single file uploads, but I'm having a problem with the rename function and multiple file uploads. I must be missing something obvious. Where are new filenames stored once the files are uploaded and renamed? (My files upload and rename fine) The names_array contains the old names, not the new ones.

    You can see a debug trace here - http://www.xcottawa.ca/tmp/easy_php_multi_rename.html

    So far I've looked at parsing the message array or creating a new array, but the class should already do it right? (But I can't find where!)

    Thanks for any help.
    Craig

    Posted 6 months ago #
  2. Olaf

    Olaf
    PHP Coder

    Hi,

    The multiple upload extension is actually an example on how to solve that kind of application and the "manual rename" function is not included.

    Maybe you can use the standard class inside a loop like:

    foreach ($_FILES as $key => $val) {
        // code upload class
    Posted 6 months ago #
  3. cstorey

    cstorey
    Member

    Really? At least, I wasn't missing the obvious.

    Ok, so I modified the multi_files class function to return the renamed values in the names_array...

    function upload_multi_files ()
    	{
    		$this->message = "";
    		if ($this->count_files()) {
    			foreach ($this->names_array as $key => $value) {
    				if ($value != "") {
    					$this->the_file = $value;
    					$new_name = $this->set_file_name();
    					if ($this->check_file_name($new_name)) {
    						if ($this->validateExtension()) {
    							$this->file_copy = $new_name;
    							$this->the_temp_file = $this->tmp_names_array[$key];
    							if (is_uploaded_file($this->the_temp_file)) {
    								if ($this->move_upload($this->the_temp_file, $this->file_copy)) {
    									$this->message[] = $this->error_text($this->error_array[$key]);
    									if ($this->rename_file)
    									{
    										$this->message[] = $this->error_text(16);
    
    										// ***** CDS, 2008/12/19 - Replace upload filename with unique renamed one..
    										$this->names_array[$key] = $this->file_copy;
    										// ***** 
    
    										sleep(1); // wait a seconds to get an new timestamp (if rename is set)
    									}
    
    								}
    							} else {
    								$this->message[] = $this->extra_text(1);
    								$this->message[] = $this->error_text($this->error_array[$key]);
    							}
    						} else {
    							$this->wrong_extensions++;
    						}
    					} else {
    						$this->bad_filenames++;
    					}
    				}
    			}
    			if ($this->bad_filenames > 0) $this->message[] = $this->extra_text(5);
    			if ($this->wrong_extensions > 0) {
    				$this->show_extensions();
    				$this->message[] = $this->extra_text(2);
    			}
    		} else {
    			$this->message[] = $this->extra_text(3);
    		}
    	}
    Posted 6 months ago #
  4. cstorey

    cstorey
    Member

    Oops, too quick with the submit. Basically, I only added one line..

    if ($this->rename_file)
    {
       $this->message[] = $this->error_text(16);
    
       // ***** CDS, 2008/12/19 - Replace upload filename with unique renamed one..
    
       $this->names_array[$key] = $this->file_copy;
    
       sleep(1); // wait a seconds to get an new timestamp (if rename is set)
    
    }

    Seems to work for me. Do you see any issues with it?

    Posted 6 months ago #
  5. Olaf

    Olaf
    PHP Coder

    sure this is possible too...

    Posted 6 months ago #

RSS feed for this topic

Reply

You must log in to post.