I'm trying to deal with uploading images,
here's the function in my ImagesController that handles the upload:
function upload() {
// Upload an image
if (!empty($this->data)) {
$new_name
=substr( str_shuffle(
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ) ,
0 , 15 );
$this->data['Image']['Image']['name'] = $new_name.$this-
>data['Image']['Image']['name'];
//create a new variable to pass to the Upload model, from
this Image Model
$new_data = array('Upload' =>array(
'user_id' => $this->Session->read('User.id'),
'size' => $this->data['Image']['Image']['size'],
'name' => $this->data['Image']['Image']['name'],
'type' => $this->data['Image']['Image']['type']
)
);
$this->loadModel('Upload');
//Pass the $new_data to the upload function
in Upload model
if($this->Image->upload($this->data) && $this->Upload-
>upload($new_data)) {
$this->Session->setFlash('The image was successfully
uploaded.');
} else{
$this->Session->setFlash('There was an error with the
uploaded file.');
}
}
}
then I have an Upload model, with an "upload" function also, to store
image information in database, here it is:
function upload($data = null){
$new_data = $data['Upload'];
print_r($new_data);
print_r($data);
if(empty($data)){
return false;
}
return true;
}
here's the output of print_r($new_data):
Notice (8): Undefined index: Upload [APP\models\upload.php, line 19]
Array ( [user_id] => 5 [size] => 67231 [name] =>
EgMVbKhB3OrLj2vEditing Users.JPG [type] => image/jpeg )
here's the output of print_r($data):
Array ( [class] => Upload [alias] => Upload [id] => )
what the heck is the array above doing here? why is it passed along?
Array ( [user_id] => 5 [size] => 67231 [name] =>
S4WLDcgIEfHtqbsEditing Users.JPG [type] => image/jpeg )
how can I access only the Upload key from $data...
and how come there's another array that is passed with $new_data? all
I need is the second array from print_r($data), but everytime I access
it like: $data['Upload'], I get a notice but also a print out of the
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php