Jump to content
cristian77

PHP Copy content into a new file to a random directory..

Recommended Posts

Salut,

Am nevoie de putin ajutor in codul de mai jos. Vreau sa citesc continutul unui fisier si sa il copiez intr-un fisier creat nou dintr-un random directory:


 

<?php
error_reporting(E_ALL);

$dirname = uniqid();
mkdir($dirname);

$newFileName = '/'.$dirname.'/newfile.txt';
$newFileContent = 'someinfofile.txt';

if (file_put_contents($newFileName, $newFileContent) !== false) {
    echo "File created (" . basename($newFileName) . ")";
} else {
    echo "Cannot create file (" . basename($newFileName) . ")";
}
?>

Primesc eroare ca nu exista fisierul in directorul respectiv..

Link to comment
Share on other sites

16 minutes ago, cristian77 said:

sier

Daca folosesc linia

$newFileName = $dirname.'/newfile.txt';

Primesc eroare: Notice: Undefined variable: dirname in C:\xampp\htdocs\test1.php on line 6
 

Am incercat deasemenea varianta de mai jos aceeasi poveste:

<? 
$dirname = uniqid();
mkdir($dirname);
copy('contentfile.txt', '/'.$dirname.'/newfile.txt');
?>

 

Link to comment
Share on other sites

Functioneaza, multumesc frumos! problema este ca orice as pune in continuare spre exemplu echo('done');

Imi da asa: Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\xampp\htdocs\test.php on line 6

Iar codul simplu pus in test.php vine cu eroarea: Notice: Use of undefined constant - assumed ' ' in C:\xampp\htdocs\test.php on line 6

Cu toate ca el lucreaza.

Edited by cristian77
Link to comment
Share on other sites

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.   Paste as plain text instead

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