View Full Version : upload image + create txt file same name

07-02-2007, 01:33 AM
Good day to you all,
Is there somebody that can help me or at least point me on how to construct a piece of code that :

each time a user upload an image, a txt file is created with the samename.txt in a specific folder ?

Thanks !

07-02-2007, 01:42 AM
functions -
mkdir() - http://php.net/mkdir
thats it basically ..call the function on upload and hey presto...

07-02-2007, 06:21 AM
Here's where I am now...

//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "Upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "Upload/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "Upload/".$HTTP_POST_FILES['ufile']['name'][2];
$path4= "Upload/".$HTTP_POST_FILES['ufile']['name'][3];
$path5= "Upload/".$HTTP_POST_FILES['ufile']['name'][4];

//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
copy($HTTP_POST_FILES['ufile']['tmp_name'][3], $path4);
copy($HTTP_POST_FILES['ufile']['tmp_name'][4], $path5);

$file = "model_commentaire.html"; // A template or blank file
$newfile = "Commentaires/model_commentaire.html"; // where file gets created

$name0 = substr($HTTP_POST_FILES['ufile']['name'][0], 0, strrpos($HTTP_POST_FILES['ufile']['name'][0], '.')); // striping the extension
rename("Commentaires/model_commentaire.html" , "Commentaires/".$name0.".html"); // rename to the name of the image
$named0 = "Commentaires/".$name0.".html"; // filename and path to var
$commentaires00 = fopen($named0, 'w'); // Open file
$write = $fwrite($commentaires00, $_POST['commentaires0']); // write post commentaires0 to file
fclose($commentaires00); // close file

if (!copy($file, $newfile)) {

07-02-2007, 07:15 PM