Jump to content

Archived

This topic is now archived and is closed to further replies.

Lyricsride

Simple CHMOD issue

Recommended Posts


uploadFile.php
[code]
<?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";
}
}
?>
[/code]

form_upload.inc
[code]
<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>
[/code]

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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:
[code]mkdir("folder name",0755);[/code]
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

Share this post


Link to post
Share on other sites

×

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.