Home php Cannot Copy File

Cannot Copy File

Author

Date

Category

When you select a file and click on the button issues an error:

Warning: Copy () [Function.copy]: The Second Argument to Copy ()
FUNCTION CANNOT BE A Directory In Z: \ Home \ Prakt \ www \ 4_1_action.php on
Line 9 Error when copying a file 04.jpg

Tell me what’s the matter?


Answer 1, Authority 100%

Let’s look at the documentation: http://php.net/manual/ru/function. Copy.php

Copy – copies the source file to a file with name dest .

You are trying to give the second parameter directory.

You need to add to the end of the slash and name: Copy ($ Myfile, $ catalog. '/' $ MyFile_Name)


I also note that the else condition is redundant. You can at first check the existence of the directory, and if it is not created. The remaining file copying designs leave below.

In the end. If you imagine that you have a structure here:

- index.php (with form)
- 4_1_action.php (handler)
- images (folder with pictures, in one directory with 4_1_action.php)
 - photo_1.jpg
 - photo_2.jpg
 ...
...

The processor code will be as follows:

if (isset ($ _ files ["file"])) {
  $ catalog = "image";
  If (! is_dir ($ Catalog))
    mkdir ('image');
  $ MyFile = $ _files ["File"] ["TMP_NAME"];
  $ MyFile_Name = $ _files ["File"] ["Name"];
  If (! Copy ($ MyFile, $ Catalog. '/'.$myFile_Name))
    Echo "Error Copying File". $ MyFile_Name
}

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions