Jump to content

Couldn't copy the file error


travelkind

Recommended Posts

I have written this simple script to upload a file and am getting an error saying "Couldn't copy the file."  I have checked the syntax and haven't found an error.  Here is a snippet of the code:

 

<?

 

if ($_FILES[img1] != "") {

 

    @copy($_FILES[img1][tmp_name],

    "/html/beer/uploads/".$_FILES[img1][name1])

          or die("Couldn't copy the file.")

 

I have set the permissions on the folder permissions on the server to be read, write and execute.

 

Here is my php.ini file:

 

rg_emulation=off

file_uploads = On

upload_tmp_dir = /html/beer/uploads

memory_limit = 50M

post_max_size = 10M

upload_max_filesize = 10M

 

Should I rename the the file to php5.ini?

 

Thanks for your help.

 

Link to comment
Share on other sites

You should take off the error suppressing from copy (@) so you can actually see what's going wrong, another good idea would be to put error_reporting(E_ALL); at the top of the file. Once you do that you'll get a bunch of undefined constant errors, you should surround indexes with quotes if they're strings. Ex: $_FILES[img1] should be $_FILES['img1']. Once you do that post back the error that copy is throwing.

Link to comment
Share on other sites

Okay here is my code now:

 

<?

error_reporting(E_ALL)

if ($_FILES[img1] != "") {

 

    @copy($_FILES['img1']['tmp_name'],

    "/html/beer/uploads/".$_FILES['img1']['name1'])

          or die("Couldn't copy the file.");

 

and here is the error I am getting:

 

Parse error: syntax error, unexpected T_IF in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 3

Link to comment
Share on other sites

You didn't fix one of the indexes, or take off the error suppression from copy. Is that your whole code? If so you're never closing your if statement, which is why you're getting that error.

 

if ($_FILES['img1'] != "") {

    copy($_FILES['img1']['tmp_name'],
    "/html/beer/uploads/".$_FILES['img1']['name1'])
          or die("Couldn't copy the file.");
}

Link to comment
Share on other sites

I made your changes and got this error:

Parse error: syntax error, unexpected T_IF in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 4

 

Here is my complete code (for the php):

 

<?

 

error_reporting(E_ALL)

if ($_FILES['img1'] != "") {

 

copy($_FILES['img1']['tmp_name'], "/html/beer/uploads/".$_FILES['img1']['name1'])         

or die("Couldn't copy the file.");

 

} else {

 

    die("No input file specified");

 

}

 

?>

<HTML>

<HEAD>

<TILE>Successful File Upload</TITLE>

</HEAD>

<BODY>

<H1>Success!</H1>

 

<P>You sent: <? echo $_FILES[img1][name]; ?>,

a <? echo $_FILES['img1']['size']; ?> byte file with

a mime type of <? echo $_FILES['img1']['type']; ?>.</P>

 

</BODY>

</HTML>

 

Thanks again for your help!

Link to comment
Share on other sites

okay I added the ; and now I am getting this message / error:

 

Notice: Undefined index: name1 in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 6

 

Warning: copy(/html/beer/uploads/) [function.copy]: failed to open stream: No such file or directory in /home/content/d/l/a/dlanden/html/beer/do_upload.php on line 6

Couldn't copy the file.

 

Any ideas?

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.