Jump to content

Folder permissions and php function move_uploaded_file


Recommended Posts

Hi guys,

 

I was hoping someone could help me with a problem?

First off, I'll let you know what I have:

 

Local machine is Windows Vista

Server is apache - xampp to be precise

Developement environment is PHP 5 & MYSQL 5

 

I have a very simple script that should upload a file to my local server like so:

 

<?php 
error_reporting(E_ALL);
//'submit' button is clicked - submitting all the data
if (isset($_POST['submit'])){
	//handle file upload
	//check for the first main image upload
	if (isset($_FILES['picMain'])){
		$filename1 = $_FILES['picMain']['name'];
		//move the the file from it's temporary location on the server
		if (move_uploaded_file($filename1, 'C:/xampp/htdocs/web/uploads')){
				echo $filename1 . ' has been uploaded!';
		}else{
				echo $filename1 . ' has  not been uploaded!<br /> ERROR: ' . $_FILES['picMain']['error'];
		}
	}


	//insert all data into vehicles, vehiclesmakes, vehiclesmodels, etc..





}else{}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="form1">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type="file" name="picMain" id="picMain" />
<input type="submit" name="submit" id="submit" value="Add" />
</form>
</body>
</html>

 

What happens is that the script runs, returns the message filename1 has not been uploaded ERROR: 0, and the graphic is not uploaded.

I am confused because the Error 0 means there was no error and the file was uploaded.

 

I have double checked the uploads folder path and it is correct.

 

I have found the 'apache' process in windows task manager and the user is 'Lyndsey' - that's me! I have then tried to add permissions to the uploads folder for the user 'Lyndsey' by:

 

Right-clicking the folder

Selecting the security tab

Finding the user 'Lyndsey' and adding full access (read, write, execute, modify, full control) to that user.

Selecting the sharing tab

Clicking share

Select 'change sharing permissions'

Adding 'Lyndsey' userand making that user the owner

Clicking 'share'.

 

I also clicked advanced sharing and gave permissions here.

 

I have also looked around this forum for similar threads but found no definitive answers.

 

Anyone any ideas as to what maybe happening?

I am new to Vista and XAMPP so still finding my feet.

 

Any help greatly appreciated! Thanks in advance!

 

Lyndsey

 

 

 

 

Link to comment
Share on other sites

The problem (well, one of them at least) is that you've trying to move $_FILES['picMain']['name'] and not $_FILES['picMain']['tmp_name']; the first parameter of move_uploaded_file should be the temporary name that was automatically given to the file when it was uploaded.

 

See here for the manual page describing a basic upload process.

Link to comment
Share on other sites

Hi ronnie88, I tired turning off access control to no avail.

 

GingerRobot, that was a typo on my part. The Files array index I am referencing is $_FILES['picMain']['tmp_name'].

 

I am getting some warnings like:

 


Warning: move_uploaded_file(C:\xampp\htdocs\web\uploads) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\xampp\htdocs\web\upload.php on line 10

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php50.tmp' to 'C:\xampp\htdocs\web\uploads' in C:\xampp\htdocs\web\upload.php on line 10
C:\xampp\tmp\php50.tmp has not been uploaded!
ERROR: 0 

 

Thanks for input so far!

Any more 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.