SchweppesAle Posted November 24, 2008 Share Posted November 24, 2008 hi, I'm working on this database application for school. Most of it is coming along smoothly, however I'm required to upload a file then read its contents which are finally stored within the database. The upload part is functioning smoothly, but whenever I implement the file_get_contents() function it fails to read anything. Under phpinfo it says freads() was disabled, does that have anything to do with this function? And is there a way around it-the admin said it was disabled for security reasons. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/134066-reading-contents-of-a-file/ Share on other sites More sharing options...
SchweppesAle Posted November 24, 2008 Author Share Posted November 24, 2008 doh...not even sure if this will work now that I've read the following post -->http://www.phpfreaks.com/forums/index.php/topic,161850.0.html basically I'm trying to allow users to upload a document(doc,docx,txt,whatever) then have php read the contents of that file and post it within a blog. I'm not sure it will work out the way I intended though. Any ideas? Link to comment https://forums.phpfreaks.com/topic/134066-reading-contents-of-a-file/#findComment-697928 Share on other sites More sharing options...
SchweppesAle Posted November 25, 2008 Author Share Posted November 25, 2008 bump? Link to comment https://forums.phpfreaks.com/topic/134066-reading-contents-of-a-file/#findComment-698367 Share on other sites More sharing options...
DarkWater Posted November 25, 2008 Share Posted November 25, 2008 Any errors? Can we see how you're using file_get_contents()? What version of PHP are you running? Link to comment https://forums.phpfreaks.com/topic/134066-reading-contents-of-a-file/#findComment-698370 Share on other sites More sharing options...
.josh Posted November 25, 2008 Share Posted November 25, 2008 you can disable specific functions, yes. I don't think that disabling fread will disable file_get_contents. But it stands to reason that if the admin disabled fread, he probably disabled the other file reading functions. But... file_get_contents could be failing to read it due to any number of other reasons. You could have typoed the path or filename. The path and/or filename could not have the right read/write permissions. Maybe you didn't successfully save the uploaded file to the server (did you use move_uploaded_file to actually save the posted file?). The list goes on. Could possibly narrow it down or at least see if there was a mistake somewhere if you post some code. Link to comment https://forums.phpfreaks.com/topic/134066-reading-contents-of-a-file/#findComment-698374 Share on other sites More sharing options...
SchweppesAle Posted November 25, 2008 Author Share Posted November 25, 2008 I believe it's just not retrieving anything from the file. whenever i try to post the return value of file_get_contents it stores nothing within the BLOG column. Here's the actual code I'm using. here's a piece of the code $Resume = file_get_contents('http://www.freewarechubs.com/upload/93819.doc'); echo("$Resume"); if ($Resume !== false) { $Occupation = mysql_real_escape_string($_POST['Occupation']); $Address = mysql_real_escape_string($_POST['Address']); $City = mysql_real_escape_string($_POST['City']); $State = mysql_real_escape_string($_POST['State']); $Zip = mysql_real_escape_string($_POST['Zip']); mysql_query("INSERT INTO Employees (Name, Number, Email, Resume, Occupation, Address, City, State, Zip) VALUES('$Name', '$Number', '$Email', '$Resume', '$Occupation', '$Address', '$City', '$State', '$Zip') ") or die(mysql_error()); echo("Data Inserted"); echo("<br/>"); } else { echo("Something went wrong"); } pretty much it keeps returning Something went wrong due to the conditional, otherwise it would just leave the BLOG column blank Link to comment https://forums.phpfreaks.com/topic/134066-reading-contents-of-a-file/#findComment-698791 Share on other sites More sharing options...
SchweppesAle Posted November 25, 2008 Author Share Posted November 25, 2008 screw it, here's the entire thing <?php include("Connect.php"); DBConnect(); mysql_select_db("schweppesale_freechubs"); /*============================================================*/ /*Special thanks to http://www.php-mysql-tutorial.com/php-mysql-upload.php for file up load tutorial*/ /*=============================================================*/ $uploaddir = '../upload/'; $tmp_name = $_FILES['userfile']['tmp_name']; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo '<pre>'; if (move_uploaded_file($tmp_name, $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; /*=============================================================*/ $Name = mysql_real_escape_string($_POST['Name']); $Number = mysql_real_escape_string($_POST['Number']); $Email = mysql_real_escape_string($_POST['Email']); $Resume = file_get_contents('http://www.freewarechubs.com/upload/93819.doc'); echo("$Resume"); if ($Resume !== false) { $Occupation = mysql_real_escape_string($_POST['Occupation']); $Address = mysql_real_escape_string($_POST['Address']); $City = mysql_real_escape_string($_POST['City']); $State = mysql_real_escape_string($_POST['State']); $Zip = mysql_real_escape_string($_POST['Zip']); mysql_query("INSERT INTO Employees (Name, Number, Email, Resume, Occupation, Address, City, State, Zip) VALUES('$Name', '$Number', '$Email', '$Resume', '$Occupation', '$Address', '$City', '$State', '$Zip') ") or die(mysql_error()); echo("Data Inserted"); echo("<br/>"); } else { echo("Something went wrong"); } ?> again, not sure if this will even work. The whole reason I'm using this rather than a text field for the resumes is that I'm trying to keep the initial format of the document. (Copy and paste removes all indentation). Is there another way of doing this??? Link to comment https://forums.phpfreaks.com/topic/134066-reading-contents-of-a-file/#findComment-698793 Share on other sites More sharing options...
.josh Posted November 25, 2008 Share Posted November 25, 2008 Okay so at the top of your code you have this: $Resume = file_get_contents('http://www.freewarechubs.com/upload/93819.doc'); echo("$Resume"); does nothing echo out from that? Link to comment https://forums.phpfreaks.com/topic/134066-reading-contents-of-a-file/#findComment-698974 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.