Jump to content

copy() error


bgdonline

Recommended Posts

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);

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :(((

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.