Jump to content

create directory where they dont exists.


Go to solution Solved by Psycho,

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

  • Solution

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.