View Full Version : mkdir() pathway sequence won't work

01-27-2010, 07:38 PM
I've used mkdir() to create a directory (folder) on-the-fly. It works and no permissions problems. However, the second part of the sequence won't work.

This gets a contributors id:
$query1 = "SELECT writer_id FROM writer_page WHERE user_name = '$logname'";
$result = mysqli_query($cxn, $query1) or die ("Couldn't execute query1.");
$resultarr1 = mysqli_fetch_assoc($result);
$writer_id = $resultarr1["writer_id"];

Now I do this:

It creates a new directory and its title is the id number of the contributor.
(PS It works.)

Now I need to get the contributors uploaded file (gained by a form) into this newly created directory. BUT I can't use the new file name (the id number) in the upload_destination instruction because 1. I wouldn't know it until the folder had been created and 2. because the whole thing is supposed to be automatic. What I've been trying to do is use the id variable name in the pathway sequence which is the upload destination....and it doesn't work. Have a look.

@$upload_destin = '../../Local Root/mycontent/$writer_id'."//".$fileName;
I've tried this:
@$upload_destin = '../../Local Root/mycontent/"$writer_id"'."//".$fileName;
and this:
@$upload_destin = '../../Local Root/mycontent/'$writer_id''."//".$fileName;

No success. I guess what I'm trying to do is achieve a similar result with $writer_id as has occurred previously with the $fileName above.
Either I've got a syntactic problem or you can't use a variable name within a pathway declaration.
I've tried to find an answer but my searches aren't revealing anything.
Could someone explain what I need to do ?
Thanks -

01-27-2010, 08:57 PM
Not sure but try this...

@$upload_destin = "../../Local Root/mycontent/".$writer_id."/".$fileName;

or maybe create the folder earlier when the user signs up so you already have it ready.

01-27-2010, 09:27 PM
I tried it but it hasn't worked. The folder is created but the upload file doesn't get placed inside. Interestingly, this time I get no warnings and we move on to the next page.
Thanks -

PS prior to trying this new technique, when I was simply naming the final directory before the file name, it all worked perfectly.
The problem is how to state the variable within the pathway statement so that it is interpreted.

01-28-2010, 06:02 AM
I have tried this....


$writer_id = 1234;
$fileName = "myfile";

$upload_destin = "../../Local Root/mycontent/".$writer_id."/".$fileName;

echo $upload_destin;

and it echos out this...

../../Local Root/mycontent/1234/myfile

so the pathway statement is correct. Something else must be wrong.

Echo out $upload_destin yourself and see what it gives you.

01-28-2010, 10:11 PM
Yes you are right !!
I did the echo and this came back:
../../Local Root/mycontent//Track 1.mp3
It skipped the id variable completely.
I had a look at the script and it occurred to me that I'd moved the variable set code further down the page (seemed like a good idea at the time). I moved it back up again (as per the original post) and it worked. Basically, the variable wasn't being set early enough in the script ie $upload_destin didn't actually have a value at the time the move file operation took place.

Thanks for your persistance, it is very much appreciated.

01-29-2010, 07:25 AM
Your very welcome, thats what its all about. Good luck with it. :)