Jump to content


Photo

Simple CHMOD issue


  • Please log in to reply
6 replies to this topic

#1 Lyricsride

Lyricsride
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationQuebec

Posted 17 August 2006 - 04:14 AM


uploadFile.php
<?php
/*
	#####################################################################                                                                                     
	#  S   ## PHP5 For Dummies script page 242                          #                                                                                     
	#####################################################################                                                                                     
	+	Title: Basic Uploading Form                                                                                                                           
	+	Date: August 16th 2006                                                                                                                                
	+	Type: Tutorial                                                                                                                                        
	+	Source: PHP for Dummies 2004, page 242                                                                                                                
	+	Description: upload a file into a form, conduct basic validation, and display a confirmation to the user after                                        
*/

#####################################################################
#  1.a ## No Form posted? Then display empty form to user           #
#####################################################################
chmod("C:\\Documents and Settings\\Lyricsride\\Mes documents\\Mes images\\".$_FILES['pix']['tmp_name'], 0777);
if(!isset($_POST['upload']))
{
	require_once('form_upload.inc');
}
#####################################################################
#  2.a ## Form posted? Then validate                                #
#####################################################################
else
{
	if($_FILES['pix']['tmp_name'] == 'none')
	{
		echo "We're sorry, the file was greater than 500kb. Please try uploading a reduced filesize. Thank-you.<br />";
		require_once('form_upload.inc');
		exit();
	}
	if(!ereg('image',$_FILES['pix']['type']))
	{
		"We're sorry, the file is not an image. Please try uploading an image. Thank-you.<br />";
		require_once('form_upload.inc');
		exit();
	}
	else
	{
		$destination = 'C:\Documents and Settings\Lyricsride\Mes documents\Mes images';
		$tempFile	 = $_FILES['pix']['tmp_name'];
		move_uploaded_file($tempFile,$destination);
		echo "Your image $tempFile has been successfully uploaded to $desination";
	}
}
?>

form_upload.inc
<html>
	<head>
		<title>
			Upload Your Image
		</title>
	</head>
	<body>
		<ol>
			<li>
				Enter the name of the picture you want to upload
				to our picture archive or use the browse button
				to navigate to the picture file.
			</li>
			<li>
				When the path to the picture file shows in the text
				field, click the Upload Picture button.
			</li>
		</ol>
		<div align="center"><hr />
		<form enctype="multipart/form-data" action="uploadFile.php" method="post">
			<input type="hidden" name="MAX_FILE_SIZE" value="500000" />
			<input type="file" name="pix" size="60" />
			<input type="submit" name="upload" value="Upload" />
		</form>
	</body>
</html>

I'm trying to get this working locally to learn, but when I upload into the forum the following error displays:
"Warning: move_uploaded_file(C:\Documents and Settings\Lyricsride\Mes documents\Mes images) [function.move-uploaded-file]: failed to open stream: Permission denied in c:\server\Apache2.2\htdocs\learn_php_test\form_upload\uploadFile.php on line 42"


To get the permission i have to use chmod right? So i tried it, played around with it, but can't seemt to get it to work. This is probably a quick syntax fix or something, thanks for the help everyone.
Lyricsride

#2 hackerkts

hackerkts
  • Members
  • PipPipPip
  • Advanced Member
  • 593 posts
  • LocationSingapore
  • Age:18

Posted 17 August 2006 - 04:17 AM

Hmm... Making sure you didn't tick the read me only option.

Regards,
hackerkts

To be a coder, you must learn how to think and not to give up so easily.


#3 BillyBoB

BillyBoB
  • Members
  • PipPipPip
  • Advanced Member
  • 630 posts

Posted 17 August 2006 - 04:24 AM

did u chmod to 777?

#4 Lyricsride

Lyricsride
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationQuebec

Posted 17 August 2006 - 06:43 AM

I've never used chmod until now and am not clear on it's implementation. Other than it's presence near the top of uploadFile.php i have't done anything with it.
Lyricsride

#5 Lyricsride

Lyricsride
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationQuebec

Posted 18 August 2006 - 06:32 AM

bump.
Lyricsride

#6 omerta

omerta
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 22 August 2006 - 06:50 PM

You cannot CHMOD on Windows because it's a command for unix system, although Windows has equivalent function for changing modes (CHMOD). Try this.

1. In your windows explorer, go to the path of folder that you want to make writable C:\\Documents and Settings\\Lyricsride\\Mes documents\\Mes images\\.

2. Right click on the folder and select sharing and security, check SHARE THIS FOLDER ON THE NETWORK and ALLOW NETWORK USERS TO CHANGE MY FILE, thereafter name the folder you want to share.

3. Go to WEB SHARING and choose SHARE THIS FOLDER, and thereafter, set the type of permission that you want to use.

If in case you want to deploy your application on a live webserver in the future, by using an ftp client, simply right click on the remote folder that you want to make writable and select CHMOD (particularly on Smart ftp client and cute ftp) and set to 777, provided it is a unix hosting service.

#7 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 22 August 2006 - 07:24 PM

I spent an entire day learning about CHMOD, posted several questions on here and eventually figured it out myself after many hours spent using Google.

CHMOD can change permissions for owner, group and others. owner is you, group I'm not familiar with yet and other is everyone else on the web.

4: Read
2: Write
1: eXecute

0777 is everyone full access (1+2+4=7)

If a folder is set to 1 (eXecute) then it means the 'others' can browse the folder - I originally thought it meant 'others' can execute all files inside it - I was wrong and it was mainly this that gave me my headache.

Now if you use mkdir() in your script to make a folder be sure to include the CHMOD access rights with it:
mkdir("folder name",0755);
Give the owner full access but groups and others only read and the ability to look inside it.

Hope this helps now or in the future - just wish someone told me this at the beginning :D
Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users