cstorey posted on 2008-12-19 05:15:50 #
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
The most popular forum posts:
Comments / discussions
Olaf posted on 2008-12-19 09:33:01 #
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
cstorey posted on 2008-12-19 20:36:16 #
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);
}
}
cstorey posted on 2008-12-19 20:42:10 #
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?
Olaf posted on 2008-12-20 08:14:02 #
sure this is possible too...