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.
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
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
<?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);
?>
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.
<?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.";
}
?>
Inserting POST/GET data directly into DB queries without escaping or checking them in some fashion is highly inadvisable.
<?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.";
}
?>