Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Apache and PHP copy() function

Posted on 2003-02-27
12
Medium Priority
?
238 Views
Last Modified: 2010-04-06
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????
0
Comment
Question by:RavenClaw
  • 4
  • 2
  • 2
  • +4
12 Comments
 

Expert Comment

by:ldsnerd
ID: 8035149
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
 

Author Comment

by:RavenClaw
ID: 8040211
i donnt no what that means! im using apache 1.37 on windows XP
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:jervis
ID: 8041186
- 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
 
LVL 1

Expert Comment

by:spiritwithin
ID: 8045697
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
 
LVL 8

Accepted Solution

by:
Zlatin Zlatev earned 400 total points
ID: 8063870
@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
 
LVL 8

Expert Comment

by:inq123
ID: 8093777
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
 
LVL 8

Expert Comment

by:Zlatin Zlatev
ID: 8101476
@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
 
LVL 8

Expert Comment

by:Zlatin Zlatev
ID: 8306100
@RavenClaw, Any progress on this?
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 9115204
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
 
LVL 8

Expert Comment

by:Zlatin Zlatev
ID: 9116416
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 9306224
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question