/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] upload image + create txt file same name

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 !

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bluestarsJul 02.2007 — If $filename equals the filename of the image:

[code=php]
preg_match('/^(.*?)..*$/',$filename,$matches);
$fh = fopen($matches[1] . '.txt', 'w') or die("Can't open file!");
fwrite($fh, "The text file!");
fclose($fh);[/code]
Copy linkTweet thisAlerts:
@PeuplarchieauthorJul 02.2007 — Here's where I am now...

[code=php]

//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)) {
}

[/code]
×

Success!

Help @Peuplarchie spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...