Jump to content

Help with making txt files and folders


Elusid

Recommended Posts

Ok so here is what I need help doing. I making an affiliate uploader for my site, I got the file upload part and the file size limitation working thanks to a friend but now I need a lot more help. I also need for their to be a file TYPE limit. I only want .jpg, .gif, or .png files allowed to be uploaded. I also need every submission to make it's own folder in the pending folder that I have already made. Each folder's name should be the date and time it was submitted. Another thing I have is a text box and I need anything in that text box to be saved into a .txt file... If someone could either point me in the right direction or give me an example that would be fantastic! Thank's so much!

Here is what I have for the PHP so far BTW

[code]
<body bgcolor='000000' text='ffffff' link='880000' vlink='880000' alink='880000'>
<?php
$dir = 'pending/';
$file = $dir.basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $file)) 
      {
          if (filesize($file) <= 153600) {echo 'All your information has been uploaded successfully. One of our staff members will look it over and if it passes our inspection, it will be on as soon as possible. Thank you.';}
      } else {
          echo 'File too large';
          unlink($file);
      }
 
?>
</body>
[/code]
Link to comment
Share on other sites

ok now as far as creating a folder with the date and time of submission. There is a potenial problem with nameing the directory with just the date and time. What if you have two affilates submit at the same time. This is somewhat unlikely but...?

Anyways, what I would do is have these fields in a database table

affiliate_id autoincrement
submit_date
submit_time
domain_name or email
status

Ok when someone submitted the form I would insert there info into the database. Then call it back like this

[code=php:0]$sql = "SELECT affiliate_id, submit_date, submit_time From your_table WHERE email ='$email'";
$get_affiliate = mysql_query($sql);
if (!$get_affiliate) {
   echo "Could not successfully run query ($sql) from DB: " . mysql_error();
   exit;
}
if (mysql_num_rows($get_affiliate) == 0) {
   echo "You have no affiliates with a matching email address";
   exit;
}         
while ($rw = mysql_fetch_assoc($get_affiliate)) {
   $dir = 'pending/' . $rw['affiliate_id'] . '.' . $rw['submit_date'] . '.' . $rw['submit_time'] . '';
   mkdir("$dir", 0700);
   if (!mkdir) {
       echo"There was an error in creating the directory";
   exit;
   }
   //creating the text file
   //$text is the text from the text area
   $file = "$dir/youfile.txt";//change the name to whatever you want.
   $handle = fopen($file, "x+");
   fwrite($handle, $text);
   fclose($handle);
}
mysql_free_result($get_affiliate);[/code]

You could add this to the file that processes the affiliate registration. I would copy your registration script and then try it with this script added.

Hope this helps,
Tom
Link to comment
Share on other sites

Wow thanks! I have a quesion though. What is the MySQL account needed for? It would be nice not to need it because I only have one... but I guess I might need to upgrade my hosting plan so I can get more if I want to do more things like this. I just woke up and need to go to work but when I get back I am going to look really closley at the code and add it to my site. Thanks!!!

EDIT: Ok yea I really don't want to use MySQL. Here is my actual form that the php is reading
http://flamelicker.com/newsite/affiliates/affiliates.html I am going to keep trying some things but if any one could help without a mysql that would be great thanks!
Link to comment
Share on other sites

ok if you do not want to use a database then you can do it like this.


[code=php:0]<?php
array_pop($_POST);
if ( get_magic_quotes_gpc() ) {
    $_POST= array_map('stripslashes' $_POST);
}
/*You will need to change url, banner and comments to
what ever the field names are in the affiliates.html*/

$url = mysql_real_escape_string(trim($_POST['url']));
$banner = mysql_real_escape_string(trim($_POST['banner']));
$url = mysql_real_escape_string(trim($_POST['comments']));

if ((!$url) || (!$banner) || (!$comments)) {
    echo "You did not submit the following information";
    if (!$url) {
        echo "You did not enter a url";
    }
    if (!$banner) {
       echo "You did not enter a banner";
    }
    if (!$comments) {
        echo "You did not enter any comments";
    }
    include('affiliates.html');
    exit;
}
/*This will return the date as Month day year and the time in a 24 hour format
i.e. 20:30(8:30pm) and 07-26-2006*/
$date = date('m-d-Y');
$time = date('Hi')
$dir = "pending/$time.$date";
mkdir("$dir", 0700);
if (!mkdir)
    echo "You were not able to create a directory. You may not have the necessary permissions";
    exit;
}

$file = "$dir/commnets.text";
$handle = fopen($file, "x+");
fwrite($handle, $comments);
fclose($handle);
?>[/code]
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.