Hi,
Interesting issue I seem to have come across. I have a form that uploads an image and stores the value in a database table. The form uploads the image file OK and makes it available for processing. The issue is as follows; using move_uploaded_file to the specified directory does not work, however using copy() to this directory does.
The code currently is as follows:
$file = $_FILES['doc_path'];
$ext = array_pop(explode('.', $file['name']));
$filename = uniqid() . '.' . $ext;
if ($file['error'] == UPLOAD_ERR_NO_FILE && ! strlen($this->filename)) {
throw new Exception('Please select a file to upload');
} elseif ($file['error'] == UPLOAD_ERR_NO_FILE) {
return true; // already have a file
} elseif ($file['error']) {
throw new Exception('File upload error');
} elseif (! $file['size']) {
throw new Exception('File is of zero length');
} else {
$path = 'uploads/' . $filename;
if (! move_uploaded_file($file['tmp_name'], $path)) {
throw new Exception('Could not upload file');
}
return $filename;
}
I have checked that the target directory exists, and the directory is writable. No error is produced using move_uploaded_file() just the "Could not upload file" exception is caught.
Would have thought if this was a permissions issue then substituting move_uploaded_file for copy wouldn't work?
Any enlightenment would be appreciated.
Thanks