PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I am starting to write my own upload class but am having a problem. This is nowhere near finished but, I get this error when starting to test it Notice: Array to string conversion in sw_class_upload.php on line 14
sw_class_upload.php
<?php
class FileUpload
{
var $index; //
var $temp_file_name; //Temporary file name
var $file_name; //Preview file upload directory
var $upload_dir; //Directory to upload to
//Constructor method - pass the $_FILES index and upload directory name
function FileUpload($arr_index, $upload_dir)
{
$this->index = $arr_index;
$this->temp_file_name = $_FILES[$this->index]['tmp_name'];
$this->file_name = strtolower($_FILES[$this->index]['name']);
$this->upload_dir = $upload_dir;
}
//Do the actual upload
function move_file()
{
if ( move_uploaded_file($_FILES[$this->index]['tmp_name'], $this->upload_dir . $this->file_name) )
{
return true;
} else {
return false;
}
}
//Rename the uploaded file using the ID from the DB insert
//Using a hardcoded name for testing still
function FileRename($file)
{
rename($file, 'abc.jpg');
}
}
?>
I read somewhere else that when uploadin multiple files that you had to use userfile[]. If not then what should this be. Also in order to upload multiple files I assume I need a loop somewhere. Where would be best to put this, in the class file or the actual submit page.
You could name them differently, since your class only wants the name, basically. You could pass the associative array containing the information, instead of the name (probably a better idea)