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