I looked everywhere but I still can find the solution to this problem. I am trying to generate XML files in dedicated directories with some images etc. But I cant make directories because of the warning: Warning: mkdir(): Permission denied in C:\wamp64\www\motor\cpanel.php on line 52
/** create XML file */
function generisanje(){
$mysqli = OpenCon2();
$mysqli->query("SET NAMES 'utf8'");
$query = "SELECT CONCAT(Ime , Prezime) as Ime, Adresa, broj_Telefona, Drzava, Email, potrosac.id_Potrosaca, Mesto, postanski_Broj, vreme_Narucivanja, proizvodi.Boja, proizvodi.Naziv, proizvodi.Cena, proizvodi.Velicina, proizvodi.Priprema, proizvodi.Primer, proizvodi.Tip, proizvodi.Kolicina FROM potrosac JOIN proizvodi ON potrosac.id_Potrosaca=proizvodi.id_Potrosaca WHERE (SELECT DATE_FORMAT(potrosac.vreme_Narucivanja ,'%d-%m-%y'))=(SELECT DATE_FORMAT(SYSDATE(),'%d-%m-%y')) ";
$narudzbina = array();
//CONCAT(Ime , " ", Prezime)as Ime
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
array_push($narudzbina, $row);
}
if(count($narudzbina)){
createXMLfile($narudzbina);
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();
}
function createXMLfile($narudzbina){
$id="strasilo";
foreach ($narudzbina as $komad) {
$ime = strval($komad['Ime']);
mkdir("naruzbine ". date("d-m-Y")."/".$ime."", true);
}
}
Above, you can see part of the code that gets a query from MySQL and returns rows, and makes directories based on the Names (Ime) from rows. I am using WAMP on my Windows laptop. It's really weird because it works whenever I use a single name from the database. I need names and surnames to be presented as directory names so I need to CONCAT or put two strings together, but whenever I try something like that warning pops up and I end up with no directories.
EDIT: I am sure that $ime make this happen. if I change $ime = strval($komad['Ime']); to $ime= "some string"; Everything runs as it should but that does not math my use case.
Thank you for help!
CodePudding user response:
You're missing an argument to mkdir()
. The $recursive
argument is the third argument, you need to put the permissions before it.
mkdir("naruzbine ". date("d-m-Y")."/".$ime, 0777, true);
true
was being treated as $permissions = 0001
, so it was creating the directory with no write permissions.
CodePudding user response:
I lost my patience and did things in an easy way. So, I worked around this by contacting strings before they enter the database. So I now pull only one variable from the query and everything works as it should.