Jump to content

Illegal offset type


hschillig

Recommended Posts

When I did a var_dump on $input[$file], it spits out this:
array (size=1)
  0 => 
    object(Symfony\Component\HttpFoundation\File\UploadedFile)[9]
      private 'test' => boolean false
      private 'originalName' => string 'roi484-salesflyer-cf.pdf' (length=24)
      private 'mimeType' => string 'application/pdf' (length=15)
      private 'size' => int 286211
      private 'error' => int 0
But this is erroring out:
for($i = 0; $i < count($input[$file]); $i++)
 
It's saying:
 
illegal offset type

 

 

$file just holds 'sheet_file', the name of the input field so I know what to reference.

Any help here? Thanks!

Link to comment
Share on other sites

The entire code is this:
 

	public function insertMedia($productId, $type, $name, $description, $file, $input)
	{
		if( ! $this->validateMediaType($type) )
		{
			MsgConsole::setError('That is an invalid media type!');
			return false;
		}

		for($i = 0; $i < count($input[$file]); $i++)
		{
			// Assign variable for easier use
			$file = $input[$file][$i];

			$media = new ProductMedia();

			$media->product_id = $productId;
			$media->name = $input[$name][$i];
			$media->description = $input[$description][$i];
			$media->type = $this->getMediaTypeInt( $type );

			// Generate a unique url and attached the user_id
			$fileName = uniqid($productId.'_') . '.' . $file->guessClientExtension();

			$media->file_path = $fileName;

			if( ! $media->save() )
			{
				if($media->errors()->has($file)) {
	                MsgConsole::setError('Your file may have not generated a unique combination. Please try uploading again.');
	                return false;
	            }

				MsgConsole::setError($media->errors()->first());
				return false;
			}
			else
			{
				if( ! $this->uploadFile($file, $fileName) )
					return false;
			}
		}

		return true;
	}

It's erroring out on this line actually:

$file = $input[$file][$i];

But when I do a var_dump on it, it shows this:

object(Symfony\Component\HttpFoundation\File\UploadedFile)[9]
private 'test' => boolean false
private 'originalName' => string 'roi484-salesflyer-cf.pdf' (length=24)
private 'mimeType' => string 'application/pdf' (length=15)
private 'size' => int 286211
private 'error' => int 0

ANSWER:

Ah, it's because I was overwriting $file which was passed as an argument...

Edited by hschillig
Link to comment
Share on other sites

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.