Apache and PHP copy() function

I have apache 1.37 and php installed im using the test script to start with:

-------------------
Test.php
-------------------
<HTML>
<HEAD>
<TITLE>File Uploading Interface</TITLE>
</HEAD>
<BODY>
<TABLE>
<FORM ENCTYPE="multipart/form-data" NAME=MyForm ACTION=testupload.php METHOD="POST">
<TR><TD>Choose File</TD><TD><INPUT NAME="MyFile"
TYPE="File"></TD></TR>
<TR><TD COLSPAN="2"><INPUT NAME="submit" VALUE="Submit"
TYPE="submit"></TD></TR>
</TABLE>
</BODY>
</HTML>

and

----------------
testupload.php
----------------
<?
If($MyFile != "none") {
copy($MyFile,"$MyFile_name");
unlink($MyFile);
}
else {
echo"You did not upload any file";
}
?>








when i try to upload a file i get an error saying:

Warning: Unable to open '' for reading: Permission denied in d:\htdocs\testupload.php on line 3

Warning: unlink() failed (Permission denied) in d:\htdocs\testupload.php on line 4

any ideas?

and how to set permissions????
RavenClawAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ldsnerdCommented:
make sure you have the directory permissioned as writable. If it is just a permission problem:

chmod og+rw dir_name should work just fine.  
0
RavenClawAuthor Commented:
i donnt no what that means! im using apache 1.37 on windows XP
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

jervisCommented:
- There is no Apache 1.37 - The current Apache 1 version is 1.3.27.
- You should also state your PHP version.
- You should ensure you have set "upload_tmp_dir" in your php.ini to a valid directory.
- Your testupload.php script is flawed. Look at the example here http://www.php.net/manual/en/features.file-upload.php and work from there.
0
spiritwithinCommented:
Try using the PHP function move_uploaded_file() instead of copy().

move_uploaded_file -- Moves an uploaded file to a new location.

bool move_uploaded_file (string filename, string destination)

This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.

If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued.

This sort of check is especially important if there is any chance that anything done with uploaded files could reveal their contents to the user, or even to other users on the same system.


0
Zlatin ZlatevTechnical ArchitectCommented:
@RavenClaw, Check whether your upload folder is on NTFS partition.
If so (I suppose this) make sure the user in which context Apache is run have sufficient privileges on the upload folder (read/create/modify).
Privileges (permissions) are set using right click on the folder, selecting properties-security.

HTH,
Zlatin Zlatev

____
P.S. btw. if possible for you, move to Windows 2000 server and IIS - 2k Srv is much stable than XP Pro as web server.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
inq123Commented:
Hi, one guess is that your php is one of the latest version, which does not use $MyFile notation to get MyFile input item any more.  You have to use either $_POST['MyFile'] or $_REQUEST['MyFile'] (I prefer the latter, catches both POST and GET).
0
Zlatin ZlatevTechnical ArchitectCommented:
@RavenClaw, yep I agree with inq123 that you may not ride the right horse.
check:
print_r($MyFile);

Also note that personally I preffer using _FILES array like this:

if (($_FILES['MyFile']['size']<>0) and ($_FILES['MyFile']['error']==0)) {
  if (substr($_FILES['MyFile']['type'], 0, 6)=='image/') {
     move_uploaded_file ($_FILES['MyFile']['tmp_name'], "./".$_FILES['MyFile']['name']);
  } else {
     unlink($_FILES['MyFile']['tmp_name']);
  }
}

This will discard any uploaded file except it is valid MIME image according to client browser.

HTH
0
Zlatin ZlatevTechnical ArchitectCommented:
@RavenClaw, Any progress on this?
0
COBOLdinosaurCommented:
This question has been classified abandoned. I will make a recommendation to the
moderators on its resolution in a week or two. I appreciate any comments
that would help me to make a recommendation.

<note>
Unless it is clear to me that the question has been answered I will recommend delete.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade. It is assumed that any participant not responding to this request is no longer interested in its final disposition.
</note>

If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp


Cd&

0
Zlatin ZlatevTechnical ArchitectCommented:
According to me... My comments will solve the issue... Well maybe other experts will disagree.
It sould be problem with file-system rights (on NTFS partition in Windows XP)
or problem with the fact that th variable is not initialized properly, due to misconfiguration of the PHP engine (in this case a global collection like _FILES may solve the problem)

However the asker never returned to confirm or reject this solution.
0
COBOLdinosaurCommented:
It is time to clean this abandoned question up.

I am putting it on a clean up list for CS.

<recommendation>
points to zlatev

</recommendation>

If anyone participating in the Q disagrees with the recommendation,
please leave a comment for the mods.

Cd&

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.