0

So, I have been trying to de bug my code for hours now, and I whilst I am not a developer, and very novice to php, I cannot find my syntax or logic error:

In general, I am trying to develop a code that will create a new directory based upon some posted fields from an html form.

The abridged version of my code is this:

$inputA = 'Something Red';
$inputB = '_Old';
$inputC = '_metal';
$inputD = '_100';

$trimmedInputA = str_replace(' ', '', $InputA);
$dirStructure = '/folderName/'.$trimmedInputA;
if (mkdir($dirStructure,0777, true)){
    die('Failed to create folders...');
};

///////skipping ahead  -->  -->  -->

$file=fopen('folderName/'.$trimmedInputA.'/'.$trimmedInputA.$inputB.$inputC.$inputD.'.csv','w');
 if(!$file){
    die ("Failed to Create File");
 }

fwrite($file,$csv_data);

I am getting the second 'die' warning, and the custom folder is not being created.

The end game, taken from this example is to create a file with a URL:

http://www.domain.com/folderName/SomethingRed/SomethingRed_Old_metal_100.csv

Any ideas on my speed-bumps?

I swear I had it working yesterday, but did some other alterations to the php, and I can't remember what I did or un-did

brian-welch
  • 441
  • 1
  • 7
  • 19

1 Answers1

1

Compare, what you assign to $dirStructure and $file.

You can notice lack of leading / in fopen parameter.

Nevertheless,

echo('folderName/'.$trimmedInputA.'/'.$trimmedInputA.$inputB.$inputC.$inputD.'.csv');

would certainly help you to debug.

David Jashi
  • 4,490
  • 1
  • 21
  • 26
  • Classic tip! I may have come across the idea to echo back functions and constructions in the past, but I surely forgot it lately. Using your tip, I did finally get all the ducks in a row. thanks. +1 for that essential self help tool – brian-welch Jun 04 '13 at 17:47