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
https://forums.phpfreaks.com/topic/286355-illegal-offset-type/
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...

Link to comment
https://forums.phpfreaks.com/topic/286355-illegal-offset-type/#findComment-1469759
Share on other sites

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.