kneifelspy Posted January 13, 2009 Share Posted January 13, 2009 Okay, I am trying to set up a form where you can upload a CD review with a picture of the CD. Here is the form on reveiw.post.php <form action="review.publish.php" method="post"> <input type="text" name="cf_band" value="BAND NAME" /><br /><br /> <input type="text" name="cf_title" value="ALBUM TITLE" /><br /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> <input type="file" name="cf_photo" /><br /><br /> <textarea cols="30" rows="5" wrap="soft" name="cf_body">BODY TEXT</textarea><br /><br /> <input type="text" name="cf_web" value="BAND WEBSITE" /><br /><br /> <input type="text" name="cf_author" value="REVIEW AUTHOR" /><br /><br /> <input type="text" name="cf_timestamp" value="<? echo $timestamp; ?>" /><br /> <input type="submit" value="Post" /> </form> Here is the code to upload the data to the MySQL table, review.publish.php: // ASSUME MY LOGIN STUFF IS CORRECT// mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.'); mysql_select_db($dbname); $filetag = $_POST['cf_photo']; $filename = $_FILES['filetag']['name']; $filetype = $_FILES['filetag']['name']; $filesize = $_FILES['filetag']['size']; $tmp_filename = $_FILES['filetag']['tmp_name']; $fp = fopen($tmp_filename, 'r'); $file_content = fread($fp, filesize($tmp_filename)); fclose($fp); $cf_band = mysql_real_escape_string($_POST['cf_band']); $cf_title = mysql_real_escape_string($_POST['cf_title']); $cf_body = mysql_real_escape_string($_POST['cf_body']); $cf_web = mysql_real_escape_string($_POST['cf_web']); $cf_author = mysql_real_escape_string($_POST['cf_author']); $cf_timestamp = mysql_real_escape_string($_POST['cf_timestamp']); $query="INSERT INTO reviews VALUES ('','$cf_band', '$cf_title', '$file_content' '$cf_body', '$cf_web', '$cf_author', '$cf_timestamp')"; mysql_query($query); echo '<b>Post Successfully Added!</b><br /><br />'; mysql_close(); Here are the errors I am getting: fread(): supplied argument is not a valid stream resource fclose(): supplied argument is not a valid stream resource Can anyone help me get this running correctly!? Link to comment https://forums.phpfreaks.com/topic/140741-solved-php-mysql-fread-error/ Share on other sites More sharing options...
dawsba Posted January 14, 2009 Share Posted January 14, 2009 try this instead of $filetag = $_POST['cf_photo']; $filename = $_FILES['filetag']['name']; $filetype = $_FILES['filetag']['name']; $filesize = $_FILES['filetag']['size']; $tmp_filename = $_FILES['filetag']['tmp_name']; use $filename = $_FILES['cf_photo']['name']; $filetype = $_FILES['cf_photo']['name']; $filesize = $_FILES['cf_photo']['size']; $tmp_filename = $_FILES['cf_photo']['tmp_name']; Link to comment https://forums.phpfreaks.com/topic/140741-solved-php-mysql-fread-error/#findComment-736634 Share on other sites More sharing options...
kenrbnsn Posted January 14, 2009 Share Posted January 14, 2009 You form tag must include enctype="multipart/form-data" for the $_FILES array to be populated. Try: <form enctype="multipart/form-data" action="review.publish.php" method="post"> <input type="text" name="cf_band" value="BAND NAME" /><br /><br /> <input type="text" name="cf_title" value="ALBUM TITLE" /><br /><br /> <input type="hidden" name="MAX_FILE_SIZE" value="2000000" /> <input type="file" name="cf_photo" /><br /><br /> <textarea cols="30" rows="5" wrap="soft" name="cf_body">BODY TEXT</textarea><br /><br /> <input type="text" name="cf_web" value="BAND WEBSITE" /><br /><br /> <input type="text" name="cf_author" value="REVIEW AUTHOR" /><br /><br /> <input type="text" name="cf_timestamp" value="<? echo $timestamp; ?>" /><br /> <input type="submit" value="Post" /> </form> Ken Link to comment https://forums.phpfreaks.com/topic/140741-solved-php-mysql-fread-error/#findComment-736640 Share on other sites More sharing options...
kneifelspy Posted January 14, 2009 Author Share Posted January 14, 2009 Nevermind! The edits worked, I missed a comma in my INSERT INTO script, and now everything works PERFECTLY! Thanks so much guys! Link to comment https://forums.phpfreaks.com/topic/140741-solved-php-mysql-fread-error/#findComment-736762 Share on other sites More sharing options...
kenrbnsn Posted January 14, 2009 Share Posted January 14, 2009 Replace <?php mysql_query($query); ?> with <?php mysql_query($query) or die("Problem with the query: <span style='color:red'>$query</span><br>" . mysql_error()); ?> and see if anything is output. Ken Link to comment https://forums.phpfreaks.com/topic/140741-solved-php-mysql-fread-error/#findComment-736766 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.