I just spent an hour searching for a similar problem on here, but have been unable to find a solution. Hopefully a kind person here can help me out.
The code below works perfectly (but for one small thing). It is a script to upload files to my Web site and the information to a MySQL database:
<?
if (!empty($_POST['key'])) {
$key = ($_POST['key']);
} else {
$key = '';
}
if (!empty($_POST['artist'])) {
$artist = ($_POST['artist']);
} else {
$artist = '';
}
if (!empty($_POST['title'])) {
$title = ($_POST['title']);
} else {
$title = '';
}
$key = trim($key);
$artist = trim($artist);
$title = trim($title);
$location = "localhost";
$username = "xxx";
$password = "xxx";
$database = "xxx";
$conn = mysql_connect("$location","$username","$password");
if (!$conn) die ("Could not connect MySQL");
mysql_select_db($database,$conn) or die ("Could not open database");
$query = "INSERT INTO fmusic VALUES (NULL, '$key', '{$_FILES['file']['name']}', '{$_FILES['file']['size']}', '{$_FILES['file']['type']}', '$artist', '$title', NOW())";
$result = mysql_query($query) or die("Add failed.");
if ($result) {
$uploaddir = '/var/www/html/mp3/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
echo "<strong>The music was successfully uploaded.</strong>";
} else {
echo "An error has occurred.";
}
mysql_close($conn);
}
?>
OK, here is the problem. When the files are uploaded they are for some reason given the file permission of 600. Basically, they are forbidden. How do I change my script to make these mp3 files 744? There must be a way to do this in the script I have... anyone know how?
Thanks!