CMS, 原创

记事狗微薄同步到新浪一直40009 system error, does multipart has image 解决方案

记事狗同步新浪Error: 40009:Error: system error, does multipart has image?解决方案

如果你也在用记事狗,也在为同步新浪图片而大动肝火,不要着急了,我花了3天时间终于把这个问题搞定了,而你就不用那么费事费力去研究了,听我说说把,

经过一步一步测试,最终将问题定位到了 include/xwb/lib 下面的 oauth.class.php 这里面在处理图片的时候出现里错误,错误的行数是 510 多行左右,看下面代码 其实是个foreach 循环问题

foreach ($params as $parameter => $value) {
			if( ($parameter == 'pic' || $parameter == 'image') ){
				if(is_string($value) && $value{0} == '@')
				{
					$url = ltrim( $value , '@' );

										$ctx_userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 3.5.30729)';
					if( version_compare(PHP_VERSION, '5.0.0', '>=') ){
						$ctx_header = "Accept: *"."/"."*\r\nAccept-Language: zh-cn\r\nUser-Agent: {$ctx_userAgent}\r\n";
						$ctx = stream_context_create(array('http'=>array('timeout'=>8,'method'=>'GET','header'=>$ctx_header)));
						$content = file_get_contents( $url, 0, $ctx);

		}else{
						@ini_set('user_agent', $ctx_userAgent);
						$content = file_get_contents( $url );
					}

					$filename = reset( explode( '?' , basename( $url ) ));
					$mime = OAuthUtil::get_image_mime($url);
				}
				elseif(is_array($value))
				{
					$content = $value[2];					$filename = $value[1];					$mime = $value[0];			

				}
				//exit($content.'|'.$filename.'|'.$mine.'|'.$value);

				$multipartbody .= $MPboundary . "\r\n";
				//$multipartbody .= 'Content-Disposition: form-data; name="'.$parameter.'"; filename="' . $filename . '"'. "\r\n";
				$multipartbody .= 'Content-Disposition: form-data; name="'.$parameter.'"; filename="' . $value . '"'. "\r\n";
				//$multi
partbody .= 'Content-Type: '. $mime . "\r\n\r\n";
				$multipartbody .= 'Content-Type: '. 'multipart/form-data' . "\r\n\r\n";
				$multipartbody .= $content. "\r\n";
			} else {
				$multipartbody .= $MPboundary . "\r\n";
				$multipartbody .= 'Content-Disposition: form-data; name="'.$parameter."\"\r\n\r\n";
				$multipartbody .= $value."\r\n";

			}
        }

只要将这部分用新浪api提供的里面的这个东西替换就可以了,下面是替换成的代码

foreach ($params as $parameter => $value) { 

			//if( $parameter == 'pic' && $value{0} == '@' )
			if( in_array($parameter,array("pic","image")) && $value{0} == '@' )
			{
				$url = ltrim( $value , '@' );
				$content = file_get_contents( $url );
				$filename = reset( explode( '?' , basename( $url ) ));
				$mime = self::get_image_mime($url); 

				$multipartbody .= $MPboundary . "\r\n";
				$multipartbody .= 'Content-Disposition: form-data; name="' . $parameter . '"; filename="' . $filename . '"'. "\r\n";
				$multipartbody .= 'Content-Type: '. $mime . "\r\n\r\n";
				$multipartbody .= $content. "\r\n";
			}
			else
			{
				$multipartbody .= $MPboundary . "\r\n";
				$m
ultipartbody .= 'content-disposition: form-data; name="'.$parameter."\"\r\n\r\n";
				$multipartbody .= $value."\r\n";

			}
        }

是不是成功了呢,反正我是成功了。如果还有其他问题 就留言把。

原创文章,转载请注明出处哦。

(946)

Related Post