Jump to content

Creating Text File with Name


Warptweet

Recommended Posts

Hi there, I have an upload form.
When you upload a file, it obviously uploads.

How can I make it so that it [b]also[/b] CREATES A .TXT FILE using the SAME name as the uploaded file, EXCEPT its a .txt file and not a .swf file?

The name of the field in the browse file is uploadedfile
That would probably be like

$_POST['uploadedfile'];
to get it the name of the file.
Link to comment
https://forums.phpfreaks.com/topic/32916-creating-text-file-with-name/
Share on other sites

I use this code for my uploader.

[code]<?php
if (($_FILES["file"]["type"] == "application/x-shockwave-flash") &&
($_FILES["file"]["size"] < 20480)) {
  echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  echo "Uploading " . $_FILES["file"]["name"];
  echo " (" . $_FILES["file"]["type"] . ", ";
  echo ceil($_FILES["file"]["size"] / 1024) . " Kb).<br />";

  if (file_exists("uploads/" . $_FILES["file"]["name"])) {
    echo $_FILES["file"]["name"] . " already exists.  ";
    echo "Please delete the destination file and try again.";
  } else {
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "uploads/" . $_FILES["file"]["name"]);
    echo "File has been stored in your uploads directory.";
    $o = fopen($_POST['uploadedfile'].".txt", "w");
    $stringData = $_POST['flashname'];
    fwrite($o, $stringData);
    $stringData = $_POST['flashauthor'];
    fwrite($o, $stringData);
    fclose($o);
  }

} else
  echo "Only flash files under 20MB may be uploaded.";
?> [/code]

What I'm trying to do is add extra forms to my uploader.
Along with uploading the file, I want it to create an extra file with the same name as the uploaded file, except with a .txt extension, and in the .txt file I created, store the following...

flashname
flashauthor
flashdescription

(the above were the names of the forms whom the person who entered in the form stored their Flash Name, the Author, and the Flash Description)

Archived

This topic is now archived and is closed to further replies.

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