Jump to content


Photo

Help with making txt files and folders


  • Please log in to reply
3 replies to this topic

#1 Elusid

Elusid
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 26 July 2006 - 02:49 AM

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

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


#2 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 26 July 2006 - 05:10 AM

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

$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);

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

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux


#3 Elusid

Elusid
  • Members
  • PipPipPip
  • Advanced Member
  • 38 posts

Posted 26 July 2006 - 02:26 PM

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.c...affiliates.html I am going to keep trying some things but if any one could help without a mysql that would be great thanks!

#4 tomfmason

tomfmason
  • Staff Alumni
  • Advanced Member
  • 1,696 posts
  • Locationstealing your wifi

Posted 27 July 2006 - 01:32 AM

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


<?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); 	
?>

Traveling East in search of instruction, and West to propagate the knowledge I have had gained.

current projects: pokersource

My Blog | My Pastebin | PHP Validation class | Backtrack linux





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users