GetDotted Domains

Viewing Thread:
"still have read/write permissions problems with freeola folders"

The "Freeola Customer Forum" forum, which includes Retro Game Reviews, has been archived and is now read-only. You cannot post here or create a new thread or review on this forum.

Thu 09/08/07 at 22:41
Regular
Posts: 12
ok this is my problem..

i have written the php code to upload pictures to my htdocs/images folder.

this works fine images are being sent to the folder and then a link is sent to my mysql so as to retrieve them with a mysql command.

the images folder has read/write permissions set to all users.

but this is this the problem....

images are not shown because when i right click and view image properties of the pictures in the images folder they are being uploaded with no read/write permissions.

When i change these to allow read/write they are then shown in my gallery page.

can anyone help please
Thu 09/08/07 at 22:41
Regular
Posts: 12
ok this is my problem..

i have written the php code to upload pictures to my htdocs/images folder.

this works fine images are being sent to the folder and then a link is sent to my mysql so as to retrieve them with a mysql command.

the images folder has read/write permissions set to all users.

but this is this the problem....

images are not shown because when i right click and view image properties of the pictures in the images folder they are being uploaded with no read/write permissions.

When i change these to allow read/write they are then shown in my gallery page.

can anyone help please
Fri 10/08/07 at 11:41
Staff Moderator
"Aargh! Broken..."
Posts: 1,408
You could just use the chmod command in PHP on each file after it is saved.

<?php
$upload_directory = '/var/home/sr0000000/htdocs/images/';
$uploadfile = $upload_directory . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);
chmod($uploadfile, 0644);
?>
Fri 10/08/07 at 13:24
Regular
Posts: 12
thanks eccles so because the uploaded pictures arent showing bascially put that code in but change the settings to 777?
Fri 10/08/07 at 13:45
Staff Moderator
"Aargh! Broken..."
Posts: 1,408
0644 should be sufficient.
The way everyone can read the file but only the owner (PHP) can write to it (overwrite it). Scripts that actually do something should be chmodded to 0755 (owner can read, write and execute and everyone else can just read and execute). You shouldn't need to use 0777 permissions.
Fri 10/08/07 at 13:55
Regular
Posts: 12
thanks eccles appreciate it
Fri 10/08/07 at 18:20
Regular
Posts: 12
this is the code where can i change the chmod settings please




<?php

//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("mysql.freeola.net", "sr------", "--------") or die(mysql_error()) ;
mysql_select_db("sr------") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ;
if(move_uploaded_file ($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
Fri 10/08/07 at 18:33
Regular
"Devil in disguise"
Posts: 3,151
Not related to your chmod problems but have a look at mysql_real_escape_string

Inserting POST/GET data directly into DB queries without escaping or checking them in some fashion is highly inadvisable.
Sat 11/08/07 at 17:52
Staff Moderator
"Aargh! Broken..."
Posts: 1,408
After the upload has been checked, then add the chmod, like:


<?php

//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form
$name = mysql_real_escape_string($_POST['name']);
$email = mysql_real_escape_string($_POST['email']);
$phone = mysql_real_escape_string($_POST['phone']);
$pic=($_FILES['photo']['name']);
// Connects to your Database
mysql_connect("mysql.freeola.net", "sr------", "--------") or die(mysql_error()) ;
mysql_select_db("sr------") or die(mysql_error()) ;
//Writes the information to the database
mysql_query("INSERT INTO `employees` VALUES ('$name', '$email', '$phone', '$pic')") ;
if(move_uploaded_file ($_FILES['photo']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
if(!chmod($target, 0644)) {
echo "Unable to change file permission of".$target;
}
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>
Mon 13/08/07 at 17:14
Regular
"Devil in disguise"
Posts: 3,151
Wouldnt it be so much nicer if there was a way to show code with its formatting. *hint hint*
Mon 13/08/07 at 18:05
Staff Moderator
"Aargh! Broken..."
Posts: 1,408
Already suggested that. It may get done. You'll always loose some formatting though due to width constraints here. There is also a small problem with having a 50 character limit for one word when posting some code. I'll have to see if there's a good way to get around that.

Freeola & GetDotted are rated 5 Stars

Check out some of our customer reviews below:

Continue this excellent work...
Brilliant! As usual the careful and intuitive production that Freeola puts into everything it sets out to do, I am delighted.
Wonderful...
... and so easy-to-use even for a technophobe like me. I had my website up in a couple of hours. Thank you.
Vivien

View More Reviews

Need some help? Give us a call on 01376 55 60 60

Go to Support Centre
Feedback Close Feedback

It appears you are using an old browser, as such, some parts of the Freeola and Getdotted site will not work as intended. Using the latest version of your browser, or another browser such as Google Chrome, Mozilla Firefox, or Opera will provide a better, safer browsing experience for you.