0

i got a little script here that generates me an json out of my webform, this works very well. now i want to change the script so the file is saved in a new directory, named as my projectname. at the moment it generates the folder with all the permissions, but the file is still not saved in it, maybe there is just a little failure. can you figure out whats wrong?

$json = json_encode($info, JSON_NUMERIC_CHECK);
mkdir('../uploads/'.$projectname, 0777 , true);
chmod('../uploads/'.$projectname, 0777 , true);
$save = fopen('../uploads/'.$projectname, $projectname . ".json", "w");
fwrite($save, $json);
fclose($save);

the file and the directory should be named after the project

thanks

ggomble
  • 3
  • 1
  • How do you execute that script? If at command line, then you clearly should see a syntax error. Under a http server you need to check that servers error log file. – arkascha Jun 26 '18 at 12:04
  • @arkascha error yes, *syntax* error I don't see it. Can you please point it out? – Federico klez Culloca Jun 26 '18 at 12:05
  • @FedericoklezCulloca with `fopen('../uploads/'. $projectname . ".json", "w");` it would create just the `project.json` in the uploads folder but i want the final result to be the `project,json` in my `project-folder` – ggomble Jun 26 '18 at 12:24
  • @ggomble please check my answer. if it's still not what you want please provide an example with actual string instead of variables, so I can give a more to-the-point answer. – Federico klez Culloca Jun 26 '18 at 12:25
  • you were much faster than me :) thanks again @FedericoklezCulloca – ggomble Jun 26 '18 at 12:30
  • Seeing that you accepted @FedericoklezCulloca 's answer below I assume you now see your syntax error :-) – arkascha Jun 26 '18 at 12:38
  • @arkascha the comment about the syntax error was by me, and I still cannot see it :) – Federico klez Culloca Jun 26 '18 at 12:43

1 Answers1

0

You're passing the wrong number and thus kind of parameters to fopen. You just need to pass two parameters, that is the path of the file and the type of access required (read, write, etc.).

Supposing I'm interpreting correctly how you want to name the file, you need to do it with just those two parameters using string concatenation, that is

$save = fopen('../uploads/'.$projectname . '/' . $projectname . ".json", "w");
//                                       ^--- This is where it differs from yours
Federico klez Culloca
  • 22,898
  • 15
  • 55
  • 90