Jump to content

What's Wrong With My Variables?


ShoeLace1291

Recommended Posts

I have a script that loops through an array to upload files with CodeIgniter.  I use a foreach loop to avoid having to write the code out twice.  In CI, I get an error message saying that the variable "o"(letter o) is undefined.  The only thing that I can assume is that it's from the first letter o in the first array value called "original_file".  I don't know what's causing the script to name the variable "o".  Here's my code:

 

$files = array('original_file', 'step_screenshot');
		$attachment_errors = array();
		$upload_errors = array();
		foreach($files as $file){
			$this->upload->initialize($config);
			if($this->upload->do_upload($file)){
				$$file = $this->upload->data();
				$attachment_info = array(
						'file_name' => $$file['file_name'],
						'file_width' => $$file['file_width'],
						'file_height' => $$file['file_height'],
						'file_size' => $$file['file_size'],
						'author_id' => $member['id']
						);
				if($this->attachment->create($attachment_info)){
					$$file['insert_id'] = $this->attachment->insert_id;
				} else {
					$attachment_errors[] = 'The file '.$file.' did not attach properly.';
				}
			} else {
				$upload_errors[] = 'The file '.$file.' did not upload properly.';
			}
		}

 

The error only occurs on lines where i call the "$$file" variable.

Link to comment
https://forums.phpfreaks.com/topic/243084-whats-wrong-with-my-variables/
Share on other sites

first of all sorry about my English,

 

The problem will be structure of $$file, try to print th content :

 

 

$$file = $this->upload->data();
print_r($$file);

$attachment_info = array(
		'file_name' => $$file['file_name'],
		'file_width' => $$file['file_width'],
		'file_height' => $$file['file_height'],
		'file_size' => $$file['file_size'],
		'author_id' => $member['id']
		);
if($this->attachment->create($attachment_info)){
    // IF $$file it's not array, you can do this.
		$$file['insert_id'] = $this->attachment->insert_id;
}

 

 

nice, I never knew about those  :P

 

So, having established my ignorance please indulge me a minute - you are assigning a variable variable array variable to $$file (which is attached to $file wich is declared as the contents of $this->upload->initialize($config); which may or may not also be an array?  is that right or am I getting the totaly wrong end of the stick? :confused:

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.