Jump to content

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:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.