?
Solved

Apache and PHP copy() function

Posted on 2003-02-27
12
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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

777 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