Jump to content

Help Writing to a file!


Deanznet

Recommended Posts

I need help! I cant get this to write the correct way!

 

What i need is based on the value of what is posted to the script it has to write it in the config file and also make a folder!

 

Please help

 

 

<?php
$start = '$uploadpath=\'';
$structure = '../banner/images/'.$_POST['FOLDER'].'\';\n';

$myFile = "PHP/confup.php";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = "<?\n";
fwrite($fh, $stringData);
$stringData = "$start $structure";
fwrite($fh, $stringData);
$stringData = "?>\n";
fwrite($fh, $stringData);
fclose($fh);

// Desired folder structure


// To create the nested structure, the $recursive parameter 
// to mkdir() must be specified.

if (!mkdir($structure, 0777, true)) {
    die('Failed to create folders...');
}

// ...
?>

Link to comment
Share on other sites

There's a little problem right here:

$structure = '../banner/images/'.$_POST['FOLDER'].'\';\n';

Strings in single quotes won't evaluate special characters like \n or \r, etc. So it's literally inserting

../banner/images/';\n

into the php file.

Also, you're putting the same variable into mkdir(), which won't work.. unless you want a folder named exactly what I said above.

Link to comment
Share on other sites

I tried it.. Im having the hardest time doing this :(

 

What i need the script basicly to do is.

 

Make a folder in ../banner/images/FOLDERPOSTNAME

 

also it has to edit a php file and add

 

$uploadpath='../banner/images/FOLDERPOSTNAME ';

 

Whats the best way

Link to comment
Share on other sites

This'll do what you were trying to do:

<?php

$structure = "../banner/images/".$_POST['FOLDER'];

$myFile = "PHP/confup.php";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, "<?php \$uploadpath='$structure'; ?>");
fclose($fh);

// Desired folder structure


// To create the nested structure, the $recursive parameter 
// to mkdir() must be specified.

if (!mkdir($structure, 0775, true)) {
    die('Failed to create folders...');
}

// ...
?>

Link to comment
Share on other sites

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.