Jim R Posted November 14, 2020 Share Posted November 14, 2020 (edited) 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 November 14, 2020 by Jim R Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/ Share on other sites More sharing options...
gw1500se Posted November 14, 2020 Share Posted November 14, 2020 You have to move_uploaded_file to get it to the desired folder. However, unless I don't understand what you want to do, there is no need to move it at all. Process the file into the database as you are. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582362 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582363 Share on other sites More sharing options...
Barand Posted November 14, 2020 Share Posted November 14, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582364 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582365 Share on other sites More sharing options...
Barand Posted November 14, 2020 Share Posted November 14, 2020 The user privileges defined in the mysql database for whichever username you are connecting with. Quote Non-LOCAL load operations read text files located on the server. For security reasons, such operations require that you have the FILE privilege. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582366 Share on other sites More sharing options...
gw1500se Posted November 14, 2020 Share Posted November 14, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582367 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 I'm the admin (reseller account) so I should have all available privileges. I'm talking to Host Gator now to find out if there is something else. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582369 Share on other sites More sharing options...
gw1500se Posted November 14, 2020 Share Posted November 14, 2020 But the user running the script may not. Did you check as I suggested? Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582371 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 7 minutes ago, gw1500se said: But the user running the script may not. Did you check as I suggested? I'm the user running the script. Which command line are you referring to? I checked through cPanel through my host. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582374 Share on other sites More sharing options...
gw1500se Posted November 14, 2020 Share Posted November 14, 2020 Are you on Linux? If so 'apache' is running the script, not you. I am referring to 'mysql' from command line. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582375 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 I'm not on Linux. I'm accessing my mysql database permissions via my cPanel / phpMyAdmin. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582376 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 I have the necessary permissions, according to the tech support, and I know I have file_uploads enabled in php.ini. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582378 Share on other sites More sharing options...
gw1500se Posted November 14, 2020 Share Posted November 14, 2020 Where you are running it as a client is irrelevant. Is the MySQL server on Windows or Linux? Is the httpd server Windows or Linux? Are they the same server? Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582379 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 Looks like Linux. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582380 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 I don't have a command line. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582381 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 (edited) Hold on...checking for more information. Edited November 14, 2020 by Jim R Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582383 Share on other sites More sharing options...
gw1500se Posted November 14, 2020 Share Posted November 14, 2020 If you have PHPAdmin with admin rights then you need to check GRANTs for user 'apache'. That is likely the crux of your problem. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582385 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582387 Share on other sites More sharing options...
gw1500se Posted November 14, 2020 Share Posted November 14, 2020 Read up on GRANT. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582388 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 OK, but where do I do that? Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582390 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 There is nowhere to type the GRANT Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582399 Share on other sites More sharing options...
gw1500se Posted November 14, 2020 Share Posted November 14, 2020 You need to open a terminal session on the MySQL server and run it from the command line. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582400 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 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? Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582401 Share on other sites More sharing options...
Jim R Posted November 14, 2020 Author Share Posted November 14, 2020 I have all of Host Gator stumped. They don't know why I'm getting an access denied error. Quote Link to comment https://forums.phpfreaks.com/topic/311706-using-form-to-pass-a-file-to-be-processed/#findComment-1582403 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.