Jump to content

Using form to pass a file to be processed...


Jim R

Recommended Posts

I'll be having .txt files uploaded via a form.  Upon submission, it will be passed to another .php file to have the data entered into the database.  

It's not uploading the file to the folder, and while the trigger echoes what's set up to echo, it's loading the data into the database.  

 

Here is the form:

	 echo '<form action="/wp-content/plugins/csi_stats/csi_process.php" method="post" enctype="multipart/form-data">
	  Select Boxscore to upload:
	  <input type="file" name="fileToUpload" id="fileToUpload">
	  <input type="submit" value="Upload" name="submit">
	</form>';
	
 }

 Here is csi_process.php

$filename = $_FILES['fileToUpload']['name'];


$target_dir = "/wp-content/uploads/csi_boxscores/21/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));


// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
 // $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
 
    echo $target_file . ' Boxscore Sent';
    echo '<br>' .$filename;
    $uploadOk = 0;
  
}

$query = "
    LOAD DATA INFILE '$fileName'
     INTO TABLE a_stats
     FIELDS TERMINATED BY '|' 
     LINES TERMINATED BY '\r\n'
     IGNORE 2 Lines
    (jersey,points,2pm,2pa,3pm,3pa,ftm,fta,oreb,dreb,treb,ast,blk,stl,deflect,turn,charge,pf,tf)
    SET team = 426";

"team" will ultimately be a variable, and I'll have "game" in there too.  

 

 

 

Here is the data:

235a5d12-be10-43af-abba-e45456d9d8da
Jersey|Points|TwoPointsMade|TwoPointAttempts|ThreePointsMade|ThreePointAttempts|FreeThrowsMade|FreeThrowAttempts|OffensiveRebounds|DefensiveRebounds|Rebounds|Assists|BlockedShots|Steals|Deflections|Turnovers|Charges|PersonalFouls|TechnicalFouls
10|8|1|2|2|6|0|0|0|4|4|1|1|1|0|1|0|0|0
12|3|0|5|0|3|3|4|1|2|3|0|1|1|0|0|0|2|0
20|8|4|6|0|0|0|0|1|1|2|0|1|1|0|2|0|0|0
22|3|0|1|1|1|0|0|1|2|3|1|0|0|0|2|0|2|0
24|18|4|7|1|3|7|10|0|2|2|1|0|1|0|3|0|3|0
32|1|0|2|0|3|1|2|2|1|3|0|0|1|0|0|0|2|0
41|8|0|0|2|3|2|2|0|0|0|0|0|1|0|0|0|1|0
43|11|5|7|0|0|1|2|0|6|6|1|0|4|0|2|0|3|0
52|3|1|6|0|0|1|1|4|3|7|0|0|1|0|1|0|4|0

 

Edited by Jim R
Link to comment
Share on other sites

That's fair, and I wondered if I needed to store the file at all, but I kind of want to keep the files.  I guess there isn't a need.  

 

So I tried it with just this...

 

$filename = $_FILES['fileToUpload']['name'];


$query = "
    LOAD DATA INFILE '$fileName'
     INTO TABLE a_stats
     FIELDS TERMINATED BY '|' 
     LINES TERMINATED BY '\r\n'
     IGNORE 2 Lines
    (jersey,points,2pm,2pa,3pm,3pa,ftm,fta,oreb,dreb,treb,ast,blk,stl,deflect,turn,charge,pf,tf)
    SET team = 426";

 

It still didn't input the data.  

Link to comment
Share on other sites

2 minutes ago, Barand said:

If you aren't storing the file you need to load it from the tmp_file.

Make sure you have the privileges required to run a LOAD DATA query.

Where would I check the privileges?  I know I had checked whether or not I could write to the folder.  

 

I can store the file, but it wasn't uploading the file.  

Link to comment
Share on other sites

Log in to MySQL from the command line using the same credentials as your PHP script (usually 'apache' in Linux). Then enter the following commands:

USE DATABASE <your database name>;

SHOW PRIVILEGES;

As Barand says, you need to see the FILE privilege. If it is not there, you will need to log in as root (or have your sys admin do it) and GRANT that privilege for that database and user.

Link to comment
Share on other sites

I'm working on that.  They're telling me I have permission, but I don't.  

 

And when you (and my tech) ask me if I have permissions, csi_username has ALL permissions.  However, the error shows csi@localhost.  Not sure where to check/change csi@localhost.

Link to comment
Share on other sites

14 minutes ago, gw1500se said:

You need to open a terminal session on the MySQL server and run it from the command line.

I don't have access to that.  

I'm talking with someone now.  They don't see why I don't have permission to use Load Data.  I'll report back.  

 

Does the query, however, look good?

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.