[eluser]anthrotech[/eluser]
Hello All,
I am having problems properly uploading a file to a table in a MySQL database. Similar code outside of CI works fine.
Here is my code for uploading the file in CI.
members.php - controller file
Code:
// Validate Form input and check Image Parameters
$fileName = $_FILES['file']['name'];
$tmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];
$fileError = $_FILES['file']['error'];
if (strlen($fileName) == 0) {
$data['message'] = "Please select a file to upload.";
$content = "";
}
else {
/* Process File */
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc()) {
$fileName = addslashes($fileName);
}
}
if (strlen($this->input->post('Caption')) > 0) {
$fileCaption = $this->input->post('Caption');
}
else {
$fileCaption = "Not Provided";
}
if ($fileError > 0) {
$data['message'] .= "<br/>Please select a File before Uploading.";
}
elseif ($fileSize == 0) {
$data['message'] .= "<br />File size cannot be zero bytes.";
}
elseif ($fileSize > $this->lang->line('site_max_file_size')) {
$data['message'] .= "<br />File cannot exceed ".$this->lang->line('site_max_file_size')." bytes";
}
elseif (!in_array(end(explode(".",strtolower($fileName))),$extension_approved)) {
$data['message'] .= "<br />Must upload either a .jpg or .png file.";
}
else {
$data['message'] = "";
}
$form_data = array(
'File' => $content,
'Caption' => (string) $fileCaption,
'Size' => (int) $fileSize,
'Name' => (string) $fileName,
'Type' => (string) $this->input->post('Type'),
'Ext' => (string) $fileType,
'UserID' => (int) $this->session->userdata('userid'),
'FileDateAdded' => date('Y-m-d H:i:s'),
'FileDateEdited' => date('Y-m-d H:i:s')
);
if ($data['message'] == "") {
// Delete Photo if Replacing a Photo
if ($this->input->post('Type') == "photo") {
$this->member_model->delete_files($this->session->userdata('userid'));
}
if ($this->member_model->add_data($this->session->userdata('userid'),$form_data,'PatientFiles') === true) {
// Delete Temporary Upload File
unlink($tmpName);
// Redirect back to the main Demographics Form
$this->output->set_header('refresh:1; url="/members/display/action/photo"');
}
else {
// Error Page
$this->load->view('utils/fileuploader', $data);
}
}
else {
// Error Page
$this->load->view('utils/fileuploader', $data);
}
Data is uploaded to the Database, but photo does not show up.
I have also tried changing $content to (string) $content AND "$content" AND '$content'.
I note that are differences in the File data uploaded between CI and regular PHP5.
CI - File Data Column
�PNG\0\0\0IHDR\0\0\0�\0\0\0�\0\0\0f&\0\0yiCCPICC Profile\0\0x��gT���{r\"�
Custom PHP5 - File Data Column
�PNGIHDR