PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 25th, 2005, 02:38 PM
webmanc webmanc is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 4 webmanc User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 51 sec
Reputation Power: 0
Uploading and parsing a file into a table

I am having trouble writing a script that use a form to take in a file to parse it into a selected table. My script is bellow. When i run the script by hitting the submit button nothing happens and the page refreshes and give no error messages. Please note that I am trying to acomplish two things. One to get the file, Two to parse the file into the selected table.

<?php

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)

{

$fileName = $_FILES['userfile']['name'];

$tmpName = $_FILES['userfile']['tmp_name'];



if($tmpName)

{

print "File Name: $File_name<p>\n";

print "File Size: $File_size<p>\n";

if(move_uploaded_file ($_FILES['File']['tmp_name'], $_FILES['File']['name']) or die ('Could not upload'))

{



$fp = fopen($tmpName, 'r');

$content = fread($fp, filesize($tmpName));

$content = addslashes($content);

fclose($fp);



if(!get_magic_quotes_gpc())

{

$fileName = addslashes($fileName);

}



# first get a mysql connection as per the FAQ


//function that connects to the dba so that I can insert data into the selected table
hookUpDb2();





$query = "INSERT INTO 2004Scores (fileName, content ) ".

"VALUES ('$fileName','$content')";



mysql_query($query) or die('Error, query failed');

include 'library/closedb.php';



echo "<br>File $fileName uploaded<br>";



}

print "Your file uploaded successfully!<p>\n";



}

else

{

print "Was unable to upload file!<p>\n";

}

unlink($tmpName);//deletes file

}





?>




<form method="post" action="<?php echo($PHP_SELF) ?>" >
<table class="formBg" align="center" width="42%" border="1" cellspacing="0" cellpadding="2">
<tr valign="top">
<td width="43%">Choose Table here</td>
<td width="57%">
<select class="dropdownMedium" name="chooseTable">
<option selected value="0">--- Choose table here ---</option>
<?php getTableName(); ?>
</select>
<input class="medium" type="hidden" name="TableName" value="<?php print(unFormatData($row[1])); ?>">
</td>
</tr>
<tr valign="top">
<td width="43%">Choose File here</td>
<td width="57%">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input type="file" name="File" size=20>
<!--input name="userfile" type="file" id="userfile"> -->
</td>
</tr>

<tr valign="top">
<td width="43%"> </td>
<td width="57%">
<input name="upload" type="submit" class="box" id="upload" value=" Upload ">
<input type="reset" name="reset" value="Reset">
</td>
</tr>
</table>
</form>

Reply With Quote
  #2  
Old February 25th, 2005, 04:55 PM
Madpawn Madpawn is offline
My beat is correct.
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 339 Madpawn User rank is Private First Class (20 - 50 Reputation Level)Madpawn User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 22 h 3 m 33 sec
Reputation Power: 5
To upload files, you must have 'enctype="multipart/form-data"' in your opening form tag. It's probably not processing the form, so you first if() is failing -- it'd help if you added and else clause to tell you if that if fails.

Also, please wrap your codes in php tags when posting ( [ PHP ] [ /PHP ] without the spaces between PHP and the brackets). It color-codes and allows indention, making it much easier to read.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Uploading and parsing a file into a table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT