doufangzhang4454
2013-01-21 06:49
浏览 77
已采纳

file_get_contents()期望参数1为字符串,

I am trying to make an image upoad form. The following is the code for the form

<table align="center">
<form enctype="multipart/form-data" action="register.php" method="post" onsubmit="return vaidate();" >
<tr><td>
Username:</td><td><input type="text"id="user" name="user"> </td> </tr>
<tr><td>
Password:</td><td><input type="password" id="pass" name="pass" ></td></tr>
<tr><td>
Confirm Password:</td><td><input type="password" id="cpass" name="cpass" onchange="validate()" ></td><td> <div id="error"></div></tr>
<tr ><td>
Profile Picture: </td> <td> <input name="userfile[]" type="file" />
</td>
</tr>
<tr align="center"><td colspan="2">
<input id="submit" align="center" type="submit" > </td>
</form>

and the recieving php page is

if(isset($_FILES['userfile'])){

            $imgData =addslashes (file_get_contents($_FILES['userfile']));
            $query = 'INSERT INTO users (User,Password,Picure) VALUES ("'.$_POST["user"].'","'.$_POST["pass"].'","'.$imgData.' ")';
            }

        else
        {
        $query = 'INSERT INTO users (User,Password,) VALUES ("'.$_POST["user"].'","'.$_POST["pass"].' ")';
        }

but i keep getting the error

file_get_contents() expects parameter 1 to be string, array given

Any solutions please?

On the suggestion of the answers i replaced with the following

$imgData =addslashes (file_get_contents($_FILES['userfile']["tmp_name"][0]));

but now my query wont run. on printing $query i realised there is no ") at the end of the string as concatenated by the function. Any ideas?

the output of echo $query is

INSERT INTO users (User,Password,Picure) VALUES ("12312312","1122","ÿØÿà\0JFIF\0\0\0d\0d\0\0ÿì\0Ducky\0\0\0\0\0P\0\0ÿî\0Adobe\0dÀ\0\0\0ÿÛ\0„\0               ÿÀ\0\07\0Î\0ÿÄ\0©\0\0\0\0\0\0\0\0\0\0\0\0   \0\0\0\0\0\0\0\0\0\0\0\0\0\0   \0\0\0\0!1  Aa\"Q2q‘BR#bÓ–XrÒ$ð±ñ‚3CcÔ&\0\0\0\0\0\0\0!1AQaq‘¡±Ñ\"2BðÁRá²#3$ÿÚ\0\0\0?\0?gà >žâû9ÜFùw2à   Ùܧ!ÃðÊ:úKØ°¨òÉMë+:\0ô•6Oø? 8ÓqSÃ#sÀ$Õ\'¾ŽI$ÀQn½µ;NÝ\\#~¬÷v6òãÏŒuËHîGD‹ßËQ:/¢?œ9éÔ’tÔqç–¿ŽHv±ÀÔèQcnæÈ\\àEðÔ|ÿ\0ñã6œ*ê>*êýA4B@n¦smöÛ;Ïl_C1*9¶jqÍ:JØeKmùµô¤‰ƒõâUýUy7;—ÿ\0²œ    ð7ÿ\0\'¡Ìz¯ê¯ýåÜþzæS¾cùòp~<}UýT³»ZÃl°ß6—ºžýÌ|~<ˉrHó}U‡T×›:%?KK|¶žZô¤k©çÆõáÓ¸ŒpZ;v‘ªpŽ+UuUÔ8*­Ö9r<ø”UWPà(UÔ.*ëõp!WP« º‡QU~¡À…ZŽ\"¨Vë?ÇÉB® xŠ¡_QÁT*Ôxq(ZÛ›XTTö—vNˆõÔñ`ùðCÐ]qG]<’xÝĪ     %E–ÇÜ‹»—í-å×îzá@Ÿ9ù0 }²µÁ—\\*C(Rãt¡:$jxÙ&ܧò~tºi;ÜÛÍ{{È··}s\'²&î¬,gcþlxÑš‰OPÙeå Gi¡õ¾ÓÚë¯$‚=J(Ù8Ž1JȘ–’=ÑïqA~ÛÜ‹»7®®åTîƒê\'XÉ“Wu•®zhÎ8TÓ)+Œ£¢¢y“áãâKæñ6ûh[Ž©Y½–¦Ž]&«Ý}èvÆU+w\'&ÝÛg¥NÍî\"E*k’ÚÄJø,!qÅ«©kuÑÒžI^½Iæî\'IZQ d5+Ø¿xe}Sg±ïgºû9Ë°‘¿cN­]E¸“}#žº#„5§/‚tâØãíÚ)°x®.º•ßr$}‡wƒœw—Oí»¸v îž;–UIzªÆÒt¹IEœÚPÒÒ’¤©iêJ’ªéQÈØ2ݾ¬_)¯UzÎèÊv?Zo½¾ÔGzPÙœG©yï°W\0€Èêë\'ÈðHN¼%ü©Þqí)€†6ý£ÉDkyrÈYÞën_Y_¦¯!¿Ÿ*ªºAˆìCSÊÛi´è”€ØHåÆâÞ3mmkAOœ”‡8‘Õi]†Æ2j ÏÝlÓ¬ÈãI–Æ3µm    ™m 2*s%ä) ¨ºÒu^Dp‹œ¹psXÓMpLxèƒ.EÞoo; `B¦ì¾%Iq·R¥PWõ¶ABò£Ó:…òñéKzü¸bÉl˜h<ªª–\\8WÖñ¾á7מ‹ZI\'™$üx}ncnæÔÓÚ–Iy(qJsÝ}q­±²¤rØåû§ut¹   ÌnâÅôUUHi   n48q’Øy× Qqߥ#D„¬Sáü§*ë ÊÛ=*Ôú_G[ÅÛ|½y0Õ?o­ØÎ7Ÿ·ZÜÓq2ä¹I¾µ…2Ím4ºu%¤t2”\'’V>g98YÛZ((šÙHé#©)–û‡÷ážm–ãÒí.ÅåI¢³Ä›wí¦#ÊS’ä õ >‡ÓjóÑ:•-  Ôt(_ÉX_ ÀäkÛ²×ma\\ç³=ðïcº½ÎfŽnïL¨ÛŒQlÙîüjšÔ¯Ó…êÕ{+ÐRìΕ uBÜÐô„«¯!okkvüÇ!Åsµ–i]õ`œÇv^ç8–Ð[ÚíæÎÖÅÜî©Åż¾µ ZÉ  )”–T§®J )BO\"µ)*@§eÃ:aºC@tÔ®÷á†=P‰Ë{üî×1šä¹;ÉkDÛ‡ùphÍ[ Á\"2¢4Óó(ðõœ]»¯z\\ûÉ\\~¥÷ÁýÀ»´Á¬šÎíØäì …;W’¥±Ýþ•‡šÀâOψ“‹·ShÈmä­ÇuQ‡Æ½É)2žÕwz+ñˆîžÙ³ «í¹zR“ǧO‡\\Ìæ\0¸¨Ýs¢žK ¢¯ÊáDþ(¶á±×å:øç‚fÛêÆ]LBïà{Ž·í?u&6ÿ\0“c•ÁF+TºTµÜ,F| ‚©Œ^_/áâ·©pÑÓÖòM‘¨ñÞ™!˜±ÛSÒe:–£´‘ª–·¢R?IÐq¶+:4 M]ɼÇkžÞÁa(C¶N/YƒGSjÌ°³HE“€Š’d¹ËŒ… ü›ÊéR|4O§>ŒQBë‰m´©Ç^¡ •(ž@\09’uåƼù$!H×µ¿l¤Æ° ›ÝùÆÎu¸™6åXÓÊ’ûi’òzÄF›Œã^cÈZ•¢‡òútêVRó—‘ÏÛ£AóNíìWf‚\'tX!µÝÀ<êñ<^õØ•-¼ául$!r1uD©^CŠSZ¨•‘ÔI× œ®’¹Ù•NÐÙ\'ûí·]ï}¹ÒP‚P\"²º~…M¹tø+ñC1œâãÂÎvm±µO¹]ãc«‹º\"ñÞÎå£jû^ÝÜ•%›ÔÎPRHR¥Ü¨@AoN}M¥å8?à<$ã¢õgkt­|±LnŸ²2TC¹xøxxòðùq¸Yµ.žÇv×ûUÚîÒãϲY³´¨NEt•€%\\¨Î(_Í´:–ÿ\0òñ†äeõ.FU¢ÑÚ3d`v\'%•exæŽÛåymÔLs¢Ž©6×SÝK,0Òyu)J? \0sQ \0IŠ¬a{ƒZ*Jî犜™ßºæÇà¶Y)´’2‰–²—.ß&x3C|Â:L§R†^‘ ÔêP­><=‡„™ÿ\0ò:”Ó4µüƒ[ôµ3 Ì÷Sî[<¬ŸK·E¶0沶^°¡Žë–Im|•Ñ*[¯yJ\0ò[hJ“â’‡‹Ðð³SßOÙU“‘‚ãÌè|ý¿î8 ’“†ÎÆOj~ÜIÉ&µä]·†LÊe$ÛŠ³ÈArjÿ\0†#ÇéÓŒ„îü›Ì2­<º{ø`¯g½FEKRÖ§Q[‹%JZŽ¤¨u$ó:Ÿ5ÔH‘Õí/Úã¿Á)7¸W-dÛäñ‘:«oàÉ0Y… ô…²g:ØóÔú‘¢º´Ò®¥kÓ¾æ^[š¦¶ö\0´¢«±}½m·nxåÖ+µõò«io-¹—d§&-/¸Ûl„¡ÇuPBÒBA\'æI$ð–âêK‡ó’c-ŒQ½TK·öƒúW|· ùH¥Í¯¡0þ6¬Kcõ¤6ÖÝ]Ø=Ë9(£ÈíE¿´â*»röòÎsù%©7ѳ«Z\\©Ít™s2\'c¶ ?q´u>ç1ô!@¢E}jn/t \'¹2¶œEn]­Ppª¬Í÷pâÖ@nVWŸî-×Kzž§æXXZñ3‘¾1ڵȈ¯éAï¥{Ænkn=´ÛAJT¦=VW|ÂW©IP0àõ$xj=Açò?ð0“ºJv+¼›òoŠ}–íê·3¹ýžÇÖWƾfâå’5A‰S¬×‚þJòzéá·!)ŽžÊyà©ZǺP…ÑY‡»q\'µISÚÃnW„ö¹_’Kd7a¹÷“ïÖTpDd¦º*U¯Àˆªu:x‡5ã#ÌM¾âƒ \0ñO8øöÅ^©¶{ÅîrY¤Ú}ž‡\'ùö¤å·±­–£!P uâ§dhÅ[àa©t”Ë\0¸rr`ƒVË`.n–îm¶Ý¡$µ˜duÕsADWßH’à> !®µ~®ÜIéÆçt  \\MÜð;TÑši¶i†[K,°„¶ËH%)HÐ$à\0>~MMz­@ÁG»Ý×w2{-ÓÅvb<É0Üj’5ôÚÄ(¥©–s–òû©–e-ëùJœþ.5 lfC™4ðI¹)IvÝc]¤à»¸[»Ÿ¸<í86¹ùÞkzTYÌim¥ªõLЈáiZÜRÎ…A   )R‚ƒù$du‰µ>åRÙ¬s¾s@Ÿy{›Ù†²s¶µŠÜiü›)¶‚Œªòž²\\j® Õ)I72Ò·\\RŸi”èÛÊÕ=z9)wËæõ&\'…~[º|MfÖP×T5ö+o]ÝmãÛ=¹Buk.Èà@œ@\'¢\"žI”æƒøWêá½Ì¢8œþ€ª3{ÀêQË÷rܦ1˜ÁvžµHbNysë%DkAÑ[J„¨\' i¢TûÍtòÓè?‡Î\"é]!Ð{JmÈ¿kGêˆ/v­¶ƒw{†Ú\\    ÖDªël‚;÷Œ”õ%UÐ5›1*–Ša…§_|hofô¢{û=é]¼{äL]    éJR4J@Ð\0>ŒÓôWâP¢MßåÇû¾Þø¡¯-mس@Ð ~á <¥ˆæ§IãmÆ;u»;½Ä¬åؤ®ïMzfY‘NÆ©ðÉ6n;ŒcófÙTS€€ÓRìÂ%?È¥8˜Í¨Fš uºÝÅßq\\waDy}¬{Rþ“ÇqùÅXNK–ÆT}³‰! ®CÃ¥Ùà+š\\˜>†Ïˆd    KÇŒÏ3{¼úM8ûúÛ· ÞsÑ\'ýå)­]ÇvG!oÌ]$;zù@ЉRYŽó=GÀ!—4#ÇNÃsÇbóÉ‚@: ɳ[€©Ý}»Ü¥Öýå¬ ƒpõPW–§Ñä­m¥d•IÓ‘Ó‡óÅêÆæu+‰ÛtGãqýÙ6£ •?m Ýæ¼Ø§ìÔS`®X²Ÿ¤Ï}kü­žd1ÖTGHRuëˆx9œê>€\'2r\0í­Twòì‡?Ë.2K¹Þe9u›³¬$\0\\zLÉ®•«¥#RJ”­?\0–†ÄÐA&$¸×Ttq.ÆóœWÛßtðÆh“¾»žÄ‚u\"ˆ#±ÆƒU(^œÞ,Â$£ÃÎWFº®3’r-uã]_‘µ`¦­´-·#R½wí«½»÷»¹¦äÜï4Ôk‹)Åà=bÜ…N—Ý\\«)HM6°¦£«^|¼´PFpÜ;Q5‹äqq!uŽË=½²Ù7Nßr2ÜÒŸ-Z¨ªÇãÖ³!¥°ô§[Sî¹ç$£mô\'CûÇÃŽ‡&.#kiÕtµ²1;q+˜wí«¼=ÀoNwº³7c¯‹‘Ìm4unŘµÅ®ŠÊ#Äe])    êKmŽ®žED«ãÇkNV8#Úpýu\\æ±|.¨]ñîÃ-»WËól×,˪²Û›ê¦i¨UXËͱ–ø‘/Ì/uqm3§OðŸÇŠü$.Z1ªíiha5%:þç6Ç4Þ]”Í6ÃÉ b–ù›,×̹°C«i0ú1°–‚Ž®´•7áà£áÅ9[ïY…ì!¦…ãìߺzjáÅ ‡åà4\'ñÐøsãAþú?âRÃÆ»¨G_n0¨{u·ØF^¤.E_JÃͧ 8 ÇCgOÀ¬ ¨üÏ©^dyqÔ¦±·c@è…¯u^Ý{»Ü¦õd»šîêcu4ÒY‰]ŠÓH-Çb@ŠÐµ”$\'¨¼§:ù¸ueÊÇofÓ]U  ìŸ+˪(¾Ý¦ûiäû½ØöëeùíU‰;í•#HC¾¶\\uÅK‡Ï!(mÕA×]9|x‹ÞY³Å± ‚{QmbèÞMQy#öðŽ‰’bÝáö/‡w[ö\\„d.໋ŽÄU|,•¸ÂlyPzÔò\"ÌŒ\\dÛ‹R›Z’žµê¨‡\"ûL3oERæѳc‘Cž?³fã)þ™{ÓŽGÌyÌ×LyÃóèZÛ_͈ǟf>j—ú×u¡Æöc­òZ2ûƒ”dt;ÉƯøz¬µý¼s?ú£=¿Ñ{`þ^Äá;göÓÇûuÝÊ×^èÈÎ$QC˜ÅM3Ôè‚–ß–Êã—Ôè—#^–œP κòÓŠw|»®#1í¥{Wh,NÝZžå¢ï+°Õî›v™Íáî^=ãô±iñºI‘¥8ûHB–ô…:[$¸óª:ƒùBGÃ\\%´{KMI® .¬Ý3ë\\4^{4öíÉ»jÞ·;-Î)2ÖcÐL­¦‡_Co32cŒ…<¥<\0é¥Ärñ+ðåÄò¨¸cAêtEµ‘‰û‰ª+\\þ?¦ þ#C÷mí½›÷½÷û­n%9_{¹‡+\'Æ’ãézdF**h¤¶:ëðáå,Ø\"p&ŸºæÈÊòàh¹Û{?ÝTg˜µ®ãîMCƒVND¼Ž‚¶4¦äNi­1BÝ)Cª.uè*éú´ã¼Üà,! ®Lãˆp.8#›$xq؉;QbÅm,ÆŠÊBm´\0”¡ H\0% \0\0‡ÃjšLIº»U„ï>{·[ƒP›œjý ‰,õt<˨=MHŽàÔ¶ëJIPýT’Hf|/i¡ÌŒ7kDÜglþŒ§¶£t¨ï)VJ¢ÁÉÛ‘_5´ë¢[S±’Ó¥#÷ú[×øG(¹Öó´økíJ¤ã]_”ŠÇ½Ÿ·útÄ£#ÏpŠþ¤ù²#=>{á?ŠôŒ$‘øúxöþr-O}>+Èã^s \"uÛ?·†Ìöíe.’ìÉÜX?Tªá¤5œÁ\\+C+#÷Ö·?uIðáMç)-Æ7§Å^‚É‘ã™OãA§‡Ë…tWÈ0­à±»Ÿ:‡{Çi¤(TG…0Ǩ‘êy*_\"1ðùñ(Zíöû¸V¿Òßçð)Z»¼cxqÚ™÷—ËÁ¨©¬h¿>Ê^\'ZÛ,¶Ÿ-J\0ý¼HEBÖâ•û¡›U¬Oºj¼Ž°:¦›­qu\0)M¹¤’P •Ò­„4“ÉZÄŠ„¢^-¼¨·b]ËAM¼ˆ®Nf¬âuÞ¡q™ZqÔ£ÔëÒ•8Nž$q j¾m^éWÙ˦›Ý-L;XuN^J¬{¬KíV2¿-É‹A”ä¥GB½4ãÀ¢¡mÄwÚä[#¹8j¬r0–›!‰Öù‚ž¿7Ìõ==<õ×M9ð)Á%°×³ýÀûÃ{±¨É…Z\'úR¹~Wš ›Qÿ\0©:¥`j•¥C˜\'‰\"Š*ãû}¾ÿ\0î¯ô…ùüB•ó{ß6qç;‰a¦ÙI[Ž+¯Ñ)HÔ“ÿ\0QðIÈuû¡Þò—«I[}EZý]^) QàB®.9Ü93ö6 ]–¨ñ׉²ãÀaÅ·-•†×&ZÛe¾²žV 5#‰njI-³ÍÛYçû¹˜_ÕWa÷Öÿ\0a®±ÀbXC±™ÐEymN²rÎ$;)BP P|¦‘ù¹%ÊÓí­nKzwf_ÚgHÆ­nº“súµl¸˜m‚‡ªZuRZ“Ô¥¤¨V€q.É5•ž9’U÷·÷Xî-.cÖ0Ñq]_6.KeJ–#Ku/Hhi¢¼¤r?t@ÉÅ,7Nòò’u“&¿3/¾%J¶MF‘Ðóˆ[ËÕCèl)Zj­:A<@RRO¸ªK‹ØŽ 2½­Ný€Å+%Kéu“âú’Ð}ö:„fŸnQ)\'E´Þ©:€e§ª TXÓc‘{|½ ÁæÖMÇÁì`ÐØ\"T·ºß¡u´º©EÀÀB•©ZÊÂG2H©Y\"ƒ€Ö@Èé­ê%EKb7Þn\"^<û%¤ãRa­m†µä„ëÈp9@\\Æ,i·²—!—&´{¼Ÿq£À¦~æµÓV•OKËW”ãÉ©Œ€¥4t+Kg^©\'äW|õoö5d“Çk·Ž ©L&_Rì«”:b—êoDýNt$ô¤ž¥#Eép=øƬ-·-´¥E5«ÀKø#v6Pzkhuñm  ø’$²ç¤z*–•:°–Я¯¬ñ à‚ZαÄÜvÏa*澕+Âã#îr¥0+“äÆi}ÉóRÏçOA_™ÓÒuê#ˆÕ%}œ{s§äÙm¶_Èı:Úw±LjE•]¢#H-¹êÓ   úâJcå„%ÏŽªO# —Q@NÒ²¼9Ù^V1Ù´rq:Xsaöð¨V¤ªu%„Ÿ]=èèfC«PŠâ‘+¥# áÇ·j7¢‹7´Ü÷/àYcÕy6ªq±øµŒŠác;F] 9\"KnÆóS ÇxýIiòž•b»pµ^#‰ØSÔFº·ªÌ(ì!ãr¬¡Uªk­
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongqieli4164 2013-01-21 06:54
    已采纳

    $_FILES['userfile'] is an array, you need to use indexes to access the specific file attributes:

    $_FILES["file"]["name"] - the name of the uploaded file
    $_FILES["file"]["type"] - the type of the uploaded file
    $_FILES["file"]["size"] - the size in kilobytes of the uploaded file
    $_FILES["file"]["tmp_name"] - the name of the temporary copy of the file stored on the   server
    $_FILES["file"]["error"] - the error code resulting from the file upload
    

    So use something like this:

    $imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
    
    点赞 打赏 评论

相关推荐 更多相似问题