PHP - Php Code Needed To Download A Cv Saved In Mysql
I have a webpage where the candidates can attach their resumes and send to the admin.These attachments are saved in the mysql db as blob datatype.In another webpage the admin needs to download all this resumes and see the content.
How will i code for that. Similar Tutorialscreate table mimi (mimiId int(11) not null, mimiBody varchar(255) ); <?php //connecting to database include_once ('conn.php'); $sql ="SELECT mimiId, mimiBody FROM mimi"; $result = mysqli_query($conn, $sql ); $mimi = mysqli_fetch_assoc($result); $mimiId ='<span>No: '.$mimi['mimiId'].'</span>'; $mimiBody ='<p class="leading text-justify">'.$mimi['mimiBody'].'</p>'; ?> //what is next? i want to download pdf or text document after clicking button or link how to do that There are two pieces to this- The HTML Form and the resulting php. I can't seem to make the leap, from the code to having the form produce the php page so others can view it until the form is again submitted overwriting the php, thus generating new content. The environment I am working in is limited to IIs 5.1 and php 5.2.17 without mySQL or other DB I'm new to php, this isn't homework,or commercialization, it's for children. I am thinking perhaps fwrite / fread but can't get my head around it. Code snipets below. Any help, please use portions of this code in hopes I can understand it Thanks Code snipet from Output.php Code: [Select] <?php $t1image = $_POST["t1image"]; $t1title = $_POST["t1title"]; $t1info = $_POST["t1info"]; $t2image = $_POST["t2image"]; $t2title = $_POST["t2title"]; $t2info = $_POST["t2info"]; ?> ... <tbody> <tr><!--Headers--> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Animal</td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Image thumb<br> </td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Date<br> </td> <td style="vertical-align: top; text-align: center; background-color: rgb(204, 255, 255);">Information<br> </td> </tr> <tr> <td style="vertical-align: top; text-align: center;">Monkey </td> <td style="vertical-align: top; text-align: center;"><img src="<?php echo $t1image.'.gif'; ?>"><!--single image presented selected from radio buttons--> </td> <td style="vertical-align: top; text-align: center;"><?php echo date("m/d/Yh:i A"); ?><!--time stamp generated when submitted form populates all fields at once--> </td> <td style="vertical-align: top; text-align: center;"><a href="#monkey" rel="facebox"><?php echo $t1title ?></a><!--Link name provided by "Title 1", that links to hidden Div generated page with content from "Info1" field--> <div id="Monkey" style="display:none"> <?php echo $t1info; ?> </div> </td> </tr> <tr> <td style="vertical-align: top; text-align: center;">Cat<br> </td> <td style="vertical-align: top; text-align: center;"><img src="<?php echo $t2image.'.gif'?>"></td> <td style="vertical-align: top; text-align: center;"><?php echo date("m/d/Yh:i A"); ?></td> <td style="vertical-align: top; text-align: center;"><a href="#Cat" rel="facebox"><?php echo $t2title ?></a> <div id="Cat" style="display:none"> <?php echo $t2info; ?> </div> </td> </tr> <tr> This replicates several times down the page around 15-20 times ( t1### - t20###) Code Snipet from HTML Form Code: [Select] <form action="animals.php" method="post"> <div style="text-align: left;"><big style="font-family: Garamond; font-weight: bold; color: rgb(51, 51, 255);"><big><big><span>Monkey</span></big></big></big><br> <table style="text-align: left; width: 110px;" border="0" cellpadding="2" cellspacing="0"> <tbody><tr> <td style="vertical-align: top;">Image thumb<br> <input type="radio" name="t1image" value="No opinion" checked><img src="eh.gif" alt="Eh"> <input type="radio" name="t1image" value="Ok"><img src="ok.gif" alt="ok"> <input type="radio" name="t1image" value="Like"><img src="like.gif" alt="Like"> <input type="radio" name="t1image" value="Dont"><img src="dont.gif" alt="Don't Like"> <input type="radio" name="t1image" value="Hate"><img src="hate.gif" alt="Hate"> <input type="radio" name="t1image" value="Other"><img src="other.gif" alt="Other"> <br> Why Title:<input type="text" name="t1title" size="45" value="..."/></td> <td style="vertical-align: top;"> Explain:<br> <textarea name="t1info" cols=45 rows=3 value="..."></textarea> </td></tr></table> <br> <!--Next--> How do I get the Form data to save to the php page for others to view? Hi guys, I am trying to create a coding which allows users to upload and download files into mysql server, but I came across some errors. The coding itself works fine on the surface, but when I uploaded the file into mysql and download them, the contents of the downloaded file was different from the original file that was upload. One good example would be when I upload txt file or doc file. I was stuck on this for quite a few days without any leads. Here are the codes: index.html <form action="add_file.php" method="post" enctype="multipart/form-data"> <input type="file" name="uploaded_file"><br> <input type="submit" value="Upload file"> </form> <p> <a href="list_files.php">See all files</a> </p> add_file.php <?php // Check if a file has been uploaded if(isset($_FILES['uploaded_file'])) { // Make sure the file was sent without errors if($_FILES['uploaded_file']['error'] == 0) { // Connect to the database $dbLink = new mysqli('localhost', 'root', 'pwd', 'myTable'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Gather all required data $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']); $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']); $data = $dbLink->real_escape_string(file_get_contents($_FILES ['uploaded_file']['tmp_name'])); $size = intval($_FILES['uploaded_file']['size']); // Create the SQL query $query = " INSERT INTO `file` ( `name`, `mime`, `size`, `data`, `created` ) VALUES ( '{$name}', '{$mime}', {$size}, '{$data}', NOW() )"; // Execute the query $result = $dbLink->query($query); // Check if it was successfull if($result) { echo 'Success! Your file was successfully added!'; } else { echo 'Error! Failed to insert the file' . "<pre>{$dbLink->error}</pre>"; } } else { echo 'An error accured while the file was being uploaded. ' . 'Error code: '. intval($_FILES['uploaded_file']['error']); } // Close the mysql connection $dbLink->close(); } else { echo 'Error! A file was not sent!'; } // Echo a link back to the main page echo '<p>Click <a href="index.html">here</a> to go back</p>'; ?> list_files.php <?php // Connect to the database $dbLink = new mysqli('localhost', 'root', 'pwd', 'myTable'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Query for a list of all existing files $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`'; $result = $dbLink->query($sql); // Check if it was successfull if($result) { // Make sure there are some files in there if($result->num_rows == 0) { echo '<p>There are no files in the database</p>'; } else { // Print the top of a table echo '<table width="100%"> <tr> <td><b>Name</b></td> <td><b>Mime</b></td> <td><b>Size (bytes)</b></td> <td><b>Created</b></td> <td><b> </b></td> </tr>'; // Print each file while($row = $result->fetch_assoc()) { echo " <tr> <td>{$row['name']}</td> <td>{$row['mime']}</td> <td>{$row['size']}</td> <td>{$row['created']}</td> <td><a href='get_file.php?id={$row['id']}'>Download</a></td> </tr>"; } // Close table echo '</table>'; } // Free the result $result->free(); } else { echo 'Error! SQL query failed:'; echo "<pre>{$dbLink->error}</pre>"; } // Close the mysql connection $dbLink->close(); ?> get_file.php <?php // Make sure an ID was passed if(isset($_GET['id'])) { // Get the ID $id = intval($_GET['id']); // Make sure the ID is in fact a valid ID if($id <= 0) { die('The ID is invalid!'); } else { // Connect to the database $dbLink = new mysqli('localhost', 'root', 'pwd', 'myTable'); if(mysqli_connect_errno()) { die("MySQL connection failed: ". mysqli_connect_error()); } // Fetch the file information $query = " SELECT `mime`, `name`, `size`, `data` FROM `file` WHERE `id` = {$id}"; $result = $dbLink->query($query); if($result) { // Make sure the result is valid if($result->num_rows == 1) { // Get the row $row = mysqli_fetch_assoc($result); // Print headers header("Content-Type: ". $row['mime']); header("Content-Length: ". $row['size']); header("Content-Disposition: attachment; filename=". $row['name']); // Print data echo $row['data']; } else { echo 'Error! No image exists with that ID.'; } // Free the mysqli resources @mysqli_free_result($result); } else { echo "Error! Query failed: <pre>{$dbLink->error}</pre>"; } @mysqli_close($dbLink); } } else { echo 'Error! No ID was passed.'; } ?> I am not too sure where the error could be but I suspect that it could be somewhere at the add_file or get_file. Seriously hope someone could help me with this bug and thanks for the trouble. Regards Jasmine Hiya guys After getting everything else working how I expected, I'm sort of struggling on the last step. Downloading I have an upload.php file that allows me to upload a file to Mysql, the fields available a upid - Primary id - Need to link this to the logged on user id name type size content The upload works perfectly Can anyone help with implmenting it to the profile.php (1st page after login) On profile page I have: Welcome "username" from Session Dynamic Table display his user id, username and password at the moment, this will be changed as not needed tho. I am using the sessions MM_Username to pass from the login The table for Login looks like: id - primary username password I assume that if I can copy the ID from login and put it in ID in Upload and add colums to dynamic table to show the upload file, will this make that file only available to logged in user? Cheers Hi, i have a table which shows some mysql data, every entry has a checkbox to select individual entries, now i want to be able to export those selected entries into a xml or txt file, i tried this: Code: [Select] <?php if($_POST['exporttxt']){ for($i=0;$i<count($_POST['checkbox']);$i++){ $export_id = $checkbox[$i]; $sql = "SELECT * FROM table WHERE id='$export_id'"; $result = mysql_query($sql);} $output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<root>\n"; if($result->num_rows > 0) { while($myrow = $result->fetch_assoc()) { $output .= "\t<row>\n"; foreach($myrow as $_name => $_value) { $output .= "\t\t<$_name>$_value</$_name>\n"; } $output .= "\t</row>\n"; } } $output .= "</root>"; } header('content-type: text/xml'); header('content-disposition: attachment; filename=data_export.xml'); echo $output; exit; ?> but that doesn't seem to work. Any hints ? I have a download section in my index.php that I'd like to add a download counter to but have no idea how to accomplish this. The existing code works perfectly but I'd like to know how many times the file is downloaded. Would prefer not to use a database. <!-- DOWNLOAD --> <div id="download" class="stylized"> <div "myform"> <div class="container"> <div class="row"> <div class="download"> <br /><br> <h1><center>FoxClone Download Page</center></h1> <?php $files = glob('download/*.iso'); $file = $files[count($files) -1]; $info = pathinfo($file); $filename = basename($file); $filename = ltrim($filename,'/'); $md5file = md5_file($file); ?> <div class="container"> <div class="divL"> <h3>Get the "<?php echo "{$filename}";?>" file (approx. 600MB)</h3> <center> <a href="<?php echo "/{$file}";?>"><img src="images/button_get-the-app.png" alt=""></a> </center><br /> <h3 style="margin-bottom: 0.5rem;">The MD5sum for "<?php echo "{$filename}";?>" is "<?php echo "{$md5file}";?> Thanks in advance, Larry Edited March 31, 2020 by larry29936added code tags Hi Guys, I have been contacted by a client who wants me to develop an application which performs the following functionality: Lets say the domain name is xyz.com . We provide an email of our domain to the person who signup on our website for our services. Lets say the email that is given to the customer is email@xyz.com The client wants to built PHP application in which if an email is sent to email@xyz.com it gets downloaded and is stored in the MySql Database. After the download there is going to be a set of algorithms which will decided whether to forward this email to the client or not on his email address. I have no idea how to accomplish this functionality. Any suggestions would be appreciated. Thanks Sadan Masroor. I have a PHP code to download one mysql table to excel sheet.what i want to do is download 2 tables in to same excel sheet.those tables are should be in different excel worksheet.please help me. this code work fine.it's download one table
<?php ob_start(); session_start(); include('dbconnection.php'); $usr= $_SESSION['fname']; header('Content-Type: text/csv'); header('Content-Disposition: attachment;filename=exported-data.csv'); $select_table=mysql_query("select * from regfarmer WHERE ffname='$usr'"); $rows = mysql_fetch_assoc($select_table); if ($rows) { getcsv(array_keys($rows)); } while($rows) { getcsv($rows); $rows = mysql_fetch_assoc($select_table); } function getcsv($no_of_field_names) { $separate = ''; foreach ($no_of_field_names as $field_name) { if (preg_match('/\\r|\\n|,|"/', $field_name)) { $field_name = '' . str_replace('', $field_name) . ''; } echo $separate . $field_name; $separate = ','; } echo "\r\n"; } ?> I'm trying to create a series of images on a page but the code won't run. (left table code out): <body> <?PHP /// fyi, the image_link field contains, e.g., artistfoldername/imagefilename.jpg $path = "artWorkImages/"; $art_id ='2'; $QUERY="SELECT art_title, about_art, image_link FROM artWork WHERE art_id = '$art_id'"; $res = mysql_query($QUERY); $num = mysql_num_rows($res); if($num>0){ while($row = mysql_fetch_array($res)){ $artist_name = $row["art_title"]; $about_art = $row["about_art"]; $image_link = $row["image_link"]; print "<img src=$path.$image_link/>"; } } ?> </body> Thanks Allen How can I create a PHP script that will trigger a download?
For example, if I have a database of files and file IDs, and have a hyperlink like this in an HTML page:
getfile.php?FileID=1001
How can I code the getfile.php file so that no matter what type the file is (ZIP, EXE, JPG, AVI, etc), it will cause the browser to prompt the user to download the file?
(Not entirely sure if this is more a PHP question or an HTML question because of how I'm approaching it...)
(The purpose of me using the getfile.php file is so that files can be physically moved around without me having to update all of the hyperlinks in the HTML files, but rather just update the paths in the SQL database instead.)
Edited by cbassett03, 02 September 2014 - 11:25 PM. Hi, this is my first post:) pretty sure i will be posting here in the future. Anyway i am having trouble with a php script which downloads a file from a mysql database. This php script works for text files and should work for most files from what i understand. When downloading a text file, the whole file is downloaded from the server. When downloading an mp3 file, only 16kb are downloaded and the file does not play. When looking at the data in the database, it displays that the full file is there (correct amount of bytes, so there is nothing wrong with my upload php script). Does anyone have any suggestions as to what I can change to make this work? Code: [Select] <?php if(isset($_GET['id'])) { // if id is set then get the file with the id from database $link=mysql_connect('localhost', 'root', ''); @mysql_select_db('filemgr') or die ("<p>Could not connect to mysql!</p>"); $id = $_GET['id']; $query = "SELECT name, type, size, content " . "FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); list($name, $type, $size, $content) = mysql_fetch_array($result); header("Content-length: $size"); header("Content-type:$type"); header("Content-Disposition: attachment; filename=$name"); echo $content; mysql_close($link); exit; } ?> Hi all: I have been going nuts trying to get this to work. I have gone through many attempts based on internet searches and examples that simply do not work. I have files stored in my MySQL db. The files cna be of any type and are being displayed in a listed report. The files are hyperlinked and clickable, but here is the issue: When I click on a file in: http://development.products-and-services.ca/cms/test.php I get: http://development.products-and-services.ca/cms/test2.php?content=DHall_CV_webdev_eng.pdf as a blank page result. The objective is to get a file download alert or to see the file in the browser. Any ideas? Im trying to get a code to find an id by name and then find a value by id this kinda works can you help? <?php $con = mysql_connect("localhost","root","password"; if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ryanteck", $con); $result = mysql_query("SELECT * FROM forum_members WHERE member_name='ryan'"); while($row = mysql_fetch_array($result)) { echo $row['member_name'] . "s Id is " . $row['id_member']; echo "<br />"; $result2 = mysql_query("SELECT * FROM forum_themes WHERE id_member= $id && variable= 'cust_uberis'"); while($row = mysql_fetch_array($result2)) or die (mysql_error()); { echo $id . "Uber Island Is " . $row['value']; echo "<br />"; } } ?> My hosts version of php just seems to automatically add the backslashes. Adding the escape string just seems to add like 3 of them rather than 1 Is this command out-of-date? Code: [Select] <?php $verificate = $_GET["ver"]; $username = $_GET["user"]; $password = $_GET["pass"]; $dbh = mysql_connect("localhost","XXXXXX_dtbusre","my database password here") or die(mysql_error()); mysql_select_db("databasename_zxq_dtb") or die(mysql_error()); $sql = "SELECT loggedin FROM entityTable WHERE username=$username"; $result = mysql_query($sql) or die(mysql_error()); while ($line = mysql_fetch_array($result)){ echo $line[0]."\t".$line[1]."\n"; } mysql_close($dbh); if($verificate === "144356455343"){ echo "SURE"; } else{ echo "NOPE"; } ?> I get this: Code: [Select] You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Hei everyone. I am new on php development and i do not have budget on offering a course so i am trying to learn my self. i need some help on the following : i want to create infopanel.php where the script will get info from. For example if user logs in the script will have to call : <?php include '/incl/infopanel.php' ; ?>The info panel to load all details from database: <?php $name='$myname'; $sur_name='$sname'; $age='$myage'; $country='$mycountry'; ?>So the info with my has to be from database . so can some one help me how to call all information from database to a specific file that i will not have to call always information on every page I hope i have been so clean with my request Hi, Ive stumbled apon a Mongo database connected to a broadcast script. I would like to change it to a Mysql database can anybody please show me an example how it will look in Mysql format
<?php /* Require the PHP wrapper for the Mxit API */ require_once ('MxitAPI.php'); /* Function to count the number of users in MongoDB */ function count_users() { $mongo = new Mongo('127.0.0.1'); $collection = $mongo->sampleapp->users; $collection->ensureIndex(array('uid' => 1)); return $collection->count(); } /* Function to get batches of users from MongoDB */ function get_users($skip=0, $limit=50) { $mongo = new Mongo('127.0.0.1'); $collection = $mongo->sampleapp->users; $collection->ensureIndex(array('mxitid' => 1, 'created_at' => 1)); $users = $collection->find()->sort(array('created_at' => 1))->skip($skip)->limit($limit); return iterator_to_array($users); } /* Instantiate the Mxit API */ $api = new MxitAPI($key, $secret); /* Set up the message */ $message = "(\*) Congratulations to our winners (\*)\n\n"; $message .= "1st place - Michael with 100 points\n"; $message .= "2nd place - Sipho with 50 points\n"; $message .= "3nd place - Carla with 25 points\n\n"; $message .= 'Good Luck! :) $Click here$'; /* Mxit Markup is included in the message, so set ContainsMarkup to true */ $contains_markup = 'true'; /* Count the number of users in the database */ $count = count_users(); /* Initialise the variable that counts how many messages have been sent */ $sent = 0; /* Keep looping through the user list, until the number of messages sent equals the number of users */ while ($sent < $count) { /* Get users in batches of 50 */ $users = get_users($sent, 50); /* The list where the user MxitIDs will be stored */ $list = array(); foreach ($users as $user) { $list[] = $user['mxitid']; $sent++; } /* If there is a problem getting an access token, retry */ $access_token = NULL; while (is_null($access_token)) { /* We are sending a message so request access to the message/send scope */ $api->get_app_token('message/send'); $token = $api->get_token(); $access_token = $token['access_token']; // Only attempt to send a message if we have a valid auth token if (!is_null($access_token)) { $users = implode(',', $list); echo "\n$sent: $users\n"; $api->send_message($app, $users, $message, $contains_markup); } } } echo "\n\nBroadcast to $sent users\n\n"; Here is my HTML code: Code: [Select] <html> <head> <title>Simple Search Form</title> </head> <body> <form name="searchform" method="get" action="/search.php"> Select Gender: <select name="gender"> <option value="Male">Male</option> <option value="Female">Female</option> </select> Select City: <select name="gender"> <option value="all">All Cities</option> <option value="newyork">New York</option> <option value="toronto">Toronto</option> <option value="london">London</option> <option value="paris">Paris</option> </select> <form> </body> </html> Here is my PHP code: <?php // get the data from the search form # get the gender (male or female) $gender = $_GET['gender']; # get the city $city = $_GET['city']; // connect to mysql and select db mysql_connect('localhost', 'root', 'pass') or die(mysql_error()); mysql_select_db($test_db); // send query $query = mysql_query("SELECT * FROM `visitors_location` WHERE gender='$gender' AND city='$city'"); $count = mysql_num_rows($query); // display data while ( $show = mysql_fetch_assoc($query) ) { echo $gender . " " . $city; } ?> My script basically shows # of males or females in a specific city. How can I show all males in all cities? In other words, let's say I want to show # of Females from all those 4 cities combined. I don't know how to do that. Can someone please help me? Hello, I have successfully made a script that will upload images to the album of my facebook page easily. Following is the link to that script http://radiations3.com/facebook/facebook_upload.php Now when i used the same script to upload status directly to my wall then the script is doing nothing kindly let me know what is the problem with my code Code: [Select] //posting to the page wall $attachment = array('message' => 'this is my message', 'access_token' => $access_token, 'name' => 'This is my demo Facebook application!', 'caption' => "Caption of the Post", 'description' => 'this is a description', 'picture' => 'http://radiations3.com/images/logo.png', ); $status = $facebook->api('/194458563914948/feed', 'POST', $attachment); // my page id =123456789 var_dump($status); The following code looks at my MySQL database at the due_owner field. This is a date field & if the due_owner date is less within 6 days of the current date, it sends an email to the $email variable. This code works great! The only issue I have is, is there ANY way for me to adjust this code so it will stop sending emails after the date listed in the due_owner field? At this time, the email address listed in teh $email variable still gets an email after the date in the due_owner field. If this is not possible, is it possible to adjust the code so it will only send the email one time? I have this code as part of a script that runs each night at midnight...Thanks Code: [Select] <?php include('connection.php'); $number_of_days_before = 6; $email = "employee1@email.org"; $reminder_details = ""; $todays_date = date( "Ymd" ); echo $todays_date; $year = substr($todays_date, 0, 4); $month = substr($todays_date, 4, 2); $date = substr($todays_date, 6, 2); $trigger_date = date("Ymd", mktime(0,0,0,$month, $date-$number_of_days_before,$year)); echo $trigger_date; $result = mysql_query( "SELECT due_owner, employee, pacts, dock, name, lname FROM psrinfo WHERE employee='Jane Doe' AND due_owner <= $trigger_date" ); $nr = mysql_num_rows( $result ); while( $row = mysql_fetch_array( $result ) ) { $reminder_details .= "Name: ".$row["fname"]." ".$row["lname"]."\n"; $reminder_details .= "PACTS Number: ".$row["pacts"]."\n"; $reminder_details .= "Dock: ".$row["dock"]."\n"; $reminder_details .= "Due to Owner: ".$row["due_owner"]."\n\n\n"; } mysql_free_result( $result ); if( !empty( $nr ) ) { $mailheader = "From: The Reminder System <$email>\nX-Mailer: Reminder\nContent-Type:text/plain"; mail("$email", "Due to Within 6 Days", "$reminder_details", "$mailheader"); } ?> |