Jump to content

create directory where they dont exists.


renfley

Recommended Posts

Ok so guys im a little stuck on some code here and could use some help..

 

ok so i have 3 rows in column and created 3 folder to match them

 

/ticket/

->folder1

->folder2

->folder3

 

Now at the end of day i might have more folders, 

 

folder4,5,6,7 ect...

 

I want to be able to check and create missing folders based on whats missing but i also want it to catch any folders that might have been deleted. 

 

here is my code, the reason it doesnt work is that as soon as it finds a folder that doesn't exists, it creates 1 folder but wont create more then that because the confition was met. and the code stops.

 

I have tried many different alternative any input would be awesome 

 

//Query DB
$sql = "SELECT DISTINCT tn from tic";
$result = mysql_query($sql) or die(mysql_error());
$loc = "../tickets/";
while ($row = mysql_fetch_assoc($result)){
$dir = $loc . $row['tn'];
if(!is_dir($dir)){
mkdir($dir); } 
elseif(is_dir($dir)){ 
}
}
exit();

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/284773-create-directory-where-they-dont-exists/
Share on other sites

Hmm, my reading of that code is that it would create a folder for every instance in the result set which does not exist. The only thing that is out of place is the elseif() which does absolutely nothing. But, it wouldn't make the code exit the process early. The code shoudl look like this

 

 

//Query DB
$sql = "SELECT DISTINCT tn from tic";
$result = mysql_query($sql) or die(mysql_error());
$loc = "../tickets/";
while ($row = mysql_fetch_assoc($result))
{
    $dir = $loc . $row['tn'];
    if(!is_dir($dir))
    {
        mkdir($dir);
    }
}
exit();

 

Have you verified the results of your query to see that it contains what you think it should?

I did i made sure that the actual folder was missing 3 dirs but when i run the script it only creates the first missing one leaving the other not to be created. 

 

i am still stuck on this ill try again this morning but any input is awesome Thanks

Archived

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

×
×
  • Create New...

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.