big-dog1965 Posted January 7, 2009 Share Posted January 7, 2009 Im trying to modify this a little and cant seem to figure it out. I have a table named Sponsor_Spn with a field Spn_Name I added fields Upload and logo I want the uploaded image to be stored in the logo field and be renamed from the Spn_Name field. then the view.php file needs to pull up the right image according to the Spn_Name Maybe theres a better script some where but this is what I found that seemed like a way to go ??? These are the files I tried, the organals are in this post up a little ways <?php // Make sure the user actually // selected and uploaded a file if (isset($_FILES['logo']) && $_FILES['logo']['size'] > 0) { // Temporary file name stored on the server $tmpName = $_FILES['upload']['tmp_name']; $logo = $_FILES['upload']['type']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); // Create the query and insert // into our database. $query = "INSERT INTO `Sponsor_Spn` (`Upload`, `logo`) VALUES ('" . $data . "', '" . $logo . "')"; $results = mysql_query($query) or die(mysql_error()); // Print results print "Thank you, your file has been uploaded."; // GET LINK $data_query = mysql_query('SELECT `id` FROM `Sponsor_Spn` WHERE `Upload` = "' . $data . '" LIMIT 20') or die(mysql_error()); $data = mysql_fetch_assoc($data_query); echo "<p>Click to view the logo: <a href='view.php?Spn_PK=" . $data['Spn_PK'] . "'>logo " . $data['Spn_PK'] . "</a>"; } else { print "No logo selected/uploaded"; } // Close our MySQL Link mysql_close($link); ?> <?php $Spn_PK = $_GET['Spn_PK']; if(!isset($Spn_PK) || empty($Spn_PK)){ die("Please select your image!"); }else{ $query = mysql_query('SELECT * FROM `Sponsor_Spn` WHERE `Spn_PK`= "'.$Spn_PK.'"'); $row = mysql_fetch_assoc($query); $content = $row['Upload']; header('Content-type: ' . $row['type'] .''); print $content; } ?> I get these error with this Warning: fread(): supplied argument is not a valid stream resource in /home/install/insert.php on line 14 Warning: fclose(): supplied argument is not a valid stream resource in /home/install/insert.php on line 16 Thank you, your file has been uploaded.Unknown column 'id' in 'field list' Link to comment https://forums.phpfreaks.com/topic/139481-solved-need-a-way-to-upload-and-view-images-inserted-to-database/page/2/#findComment-731355 Share on other sites More sharing options...
bubbasheeko Posted January 7, 2009 Share Posted January 7, 2009 I have already done the searching for contra10 here. I have pieced together this code from others that have tried. This will work for you, but I won't be able to get to your specific issue until this evening something. Hang in there and I will give you a hand with this. Link to comment https://forums.phpfreaks.com/topic/139481-solved-need-a-way-to-upload-and-view-images-inserted-to-database/page/2/#findComment-731913 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.