bgdonline Posted May 26, 2011 Share Posted May 26, 2011 Hello, im new to php and I would appreciate help with this one.... Error code is Warning: copy() expects parameter 1 to be string, array given in /path/to/file/http.class.php on line 143 Error block if (count($_FILES) > 0) { foreach ($_FILES as $name => $file) { if ($file['tmp_name']) { $newfile=dirname(__FILE__).'/../cache/'.$file['name']; $newfiles[]=$newfile; copy ($file['tmp_name'],$newfile); if ($file['tmp_name']) $this->post[$name]='@'.$newfile; } } } Line 143 copy ($file['tmp_name'],$newfile); Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/ Share on other sites More sharing options...
Fadion Posted May 26, 2011 Share Posted May 26, 2011 The $_FILES array is multidimensional and looks like this: [key 'xxx'] => { [tmp_name] => 'some_name' [name] => 'some_name_again' and so on... } When you loop through it, you're referencing keys with the $name variable and values with the $file variable. Trying to access $file['tmp_name'] makes no sense, because $file is a string. That's why copy() is giving an error, because it expects a string. Said that, there's no need to loop through $_FILES unless you have a multiple upload form and for that, you'd have to iterate the array in a slightly different case. If you have just one upload input, just access $_FILES like this: <?php echo $_FILES['input_name']['tmp_name']; ?> where 'input_name' is the name attribute of your file input. If you still aren't clear enough, I will give you a full example. Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1220522 Share on other sites More sharing options...
bgdonline Posted May 26, 2011 Author Share Posted May 26, 2011 The $_FILES array is multidimensional and looks like this: [key 'xxx'] => { [tmp_name] => 'some_name' [name] => 'some_name_again' and so on... } When you loop through it, you're referencing keys with the $name variable and values with the $file variable. Trying to access $file['tmp_name'] makes no sense, because $file is a string. That's why copy() is giving an error, because it expects a string. Said that, there's no need to loop through $_FILES unless you have a multiple upload form and for that, you'd have to iterate the array in a slightly different case. If you have just one upload input, just access $_FILES like this: <?php echo $_FILES['input_name']['tmp_name']; ?> where 'input_name' is the name attribute of your file input. If you still aren't clear enough, I will give you a full example. So i need to change line 134 to something like echo $_FILES['newfile']['tmp_name']; That part is for sending support ticket's if you whan't to see file it's in attachment [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1220524 Share on other sites More sharing options...
Adam Posted May 26, 2011 Share Posted May 26, 2011 It's better to use move_uploaded_file for files that have been uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1220539 Share on other sites More sharing options...
bgdonline Posted May 26, 2011 Author Share Posted May 26, 2011 It's better to use move_uploaded_file for files that have been uploaded. Still what ever i try result with much more errors Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1220810 Share on other sites More sharing options...
requinix Posted May 26, 2011 Share Posted May 26, 2011 GuiltyGear said something you might not have noticed: If you have just one upload input If it does not, if the field has a name like "file[]", then $_FILES is in a different structure than you might expect. $_FILES["file"]["key, like tmp_name or size"][index number] Thus you'd need another foreach on $file. Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1220833 Share on other sites More sharing options...
bgdonline Posted May 26, 2011 Author Share Posted May 26, 2011 Im definitely idiot.... Still no luck. Aditional info, this error is when sending support tickets on some bridge, with or without ticket attachment there is error **edit** Yeah if i delte that block i get no error :/ that is something, but can anyone help with fix for that block for file upload because obviously i can't make it work (( Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1220858 Share on other sites More sharing options...
jcbones Posted May 27, 2011 Share Posted May 27, 2011 When all else fails, check for expected data. echo '<pre>'; print_r($_FILES); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1220940 Share on other sites More sharing options...
requinix Posted May 29, 2011 Share Posted May 29, 2011 bgdonline: If you're going to PM people asking for (more) help, it would help to see that you have the last reply in the thread. Have you done what jcbones said? Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1222040 Share on other sites More sharing options...
bgdonline Posted May 29, 2011 Author Share Posted May 29, 2011 I thought i replyed, net is bugging back here, here is output Warning: copy() expects parameter 1 to be string, array given in /home/bgdonlin/public_html/bgdhost/test/wp-content/plugins/whmcs-bridge/includes/http.class.php on line 147 Array ( [attachments] => Array ( [name] => Array ( [0] => 1zzsubl.png ) [type] => Array ( [0] => image/png ) [tmp_name] => Array ( [0] => /tmp/phpCHSxpr ) [error] => Array ( [0] => 0 ) [size] => Array ( [0] => 5749 ) ) ) Edit when sending support ticket without image attachment i don't have error's but when upload img i get error Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1222043 Share on other sites More sharing options...
mikesta707 Posted May 29, 2011 Share Posted May 29, 2011 It seems like your upload form is an array. Thus the structure of the files array is different from what you expect. Requinix details the structure on his first post in this thread. See that thread for more information. But you are going to have to take this information in mind, and rewrite how you access the details of the uploaded image in your script Quote Link to comment https://forums.phpfreaks.com/topic/237511-copy-error/#findComment-1222059 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.