
rrayner
New Members-
Posts
7 -
Joined
-
Last visited
Everything posted by rrayner
-
I have three files which i have posted below File 1 upload.php which uploads the file to the database. File 2 downlaod.php just give you the list of file which are available to download File 3 download2.php Is the file which download the file selected. My problem is once I have downloaded the file back from the database it is saying for example when trying to open a word document "The file x.docx connot be opened because there are problems with the content" Also when downloading images from the database they will not open ethier. Is it I am doing wrong /*********************************************************************************************************************/ // // // Upload script (upload.php) // // // /*********************************************************************************************************************/ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR...l1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <?php //******************************************************* // // Open Connection to Database // //******************************************************* include ("connection.php"); ?> <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="4000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $tfileName = trim($fileName); $ttmpName = trim($tmpName); $tfileSize = trim($fileSize); $tfileType = trim($fileType); $fp = fopen($ttmpName, 'r'); $content = fread($fp, filesize($ttmpName)); $content = addslashes($content); fclose($fp); $tcontent = trim($content); if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); } $query = "INSERT INTO upload (name, size, type, content ) ". "VALUES ('$tfileName', '$tfileSize', '$tfileType', '$tcontent')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; } ?> /*********************************************************************************************************************/ // // // Download script which give you a list of files which you can download (downloadfile.php) // // // /*********************************************************************************************************************/ <html> <head> <title>Download File From MySQL</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php include ("connection.php"); $query = "SELECT id, name FROM upload"; $result = mysql_query($query) or die('Error, query failed'); if(mysql_num_rows($result) == 0) { echo "Database is empty <br>"; } else { //while(list($id, $name) = mysql_fetch_array($result)) while ($list = mysql_fetch_array($result)) { $id = $list["id"]; $name = $list["name"]; echo "ID = $id ,Name = $name"; echo "<a href='downloadfile2.php?list=$id'>$name</a> <br>"; } } ?> </body> </html> /*********************************************************************************************************************/ // // // Download script which downloads the file (downloadfile2.php) // // // /*********************************************************************************************************************/ <?php include ("connection.php"); $list = (isset($_GET['list'])) ? $_GET['list'] : ''; echo "$list"; //if(isset($_GET['id'])) if(isset($list)) { // if id is set then get the file with the id from database $id = $list; $query = "SELECT `name`,`type`,`size`,`content` FROM upload WHERE id = '$id'"; $result = mysql_query($query) or die('Error, query failed'); $list2 = mysql_fetch_array($result); $name = $list2["name"]; $type= $list2["type"]; $size= $list2["size"]; $content= $list2["content"]; $tcontent = trim($content); header("Content-Transfer-Encoding: binary"); header("Content-length: $size"); header("Content-type: $type"); header("Content-Disposition: attachment; filename=$name"); echo "$tcontent"; exit; } ?>
-
Hi All I have got a javascrit script which should on a button press check all or uncheck all checkbox's it works on the web site I got it from but when I have placed it into my php page I cant get it to work. I have tried the javascript in a none php page and it works. Below is my php page. Can some one point in the right direction please. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <?php //******************************************************* // // Open Connection to Database // //******************************************************* include ("connection.php"); //$row_ID = (isset($_GET['row_ID'])) ? $_GET['row_ID'] : ''; $row_ID = (isset($_POST['row_ID'])) ? $_POST['row_ID'] : ''; //if(isset($_POST['row_ID']) && $_POST['row_ID']) $row_ID = $_POST['row_ID']; if(isset($_POST['COMPANY_id']) && $_POST['COMPANY_id']) $COMPANY_id1 = $_POST['COMPANY_id']; //$row_ID = "RMAD100"; $SHIPDATE = date("Y-m-d"); ?> <head> <link rel="stylesheet" type="text/css" href="robtest1.css" /> </head> <body> <SCRIPT LANGUAGE="JavaScript"> <!-- // by Nannette Thacker // http://www.shiningstar.net // This script checks and unchecks boxes on a form // Checks and unchecks unlimited number in the group... // Pass the Checkbox group name... // call buttons as so: // <input type=button name="CheckAll" value="Check All" //onClick="checkAll(document.myform.list)"> // <input type=button name="UnCheckAll" value="Uncheck All" //onClick="uncheckAll(document.myform.list)"> // --> <!-- Begin function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } // End --> </script> <div id="wrapper"> <fieldset> <legend>JOB ID Update</legend> <?php include 'menus.php'; ?> <br> <br> <br> <form name="myform" action="jobid.php" method="POST"> <?php echo "<input type=\"hidden\" name=\"row_ID\" value=\"$row_ID\"><br>"; echo"<div class=\"mytext2\">Advice Note No.</div><input type=\"text\" id=\"ADVICENOTE\" name=\"ADVICENOTE\" value=\"\" title=\"ADVICENOTE\"><br> <div class=\"mytext2\">Job ID</div><input type=\"text\" id=\"JOBID2\" name=\"JOBID2\" value=\"\" title=\"JOBID2\"><br> <div class=\"mytext2\"><b>Shipped Date</b></div> <input type=\"text\" id=\"SHIPDATE\" name=\"SHIPDATE\" value=\"$SHIPDATE\" title=\"SHIPDATE\" maxlength=\"10\" size=\"10\"><br>"; echo "<div class=\"mytext2\"><b>Customer</b></div> <select name=\"COMPANY_id\"> <option>$COMPANY_id</option>"; $query1 = "SELECT DISTINCT COMPANY_id FROM addresses ORDER BY COMPANY_id ASC"; $result1 = mysql_query($query1); $num_rows=mysql_num_rows($result1); while ($row=mysql_fetch_array($result1)) { $COMPANY_id = $row["COMPANY_id"]; echo "<option value=\"$COMPANY_id\">$COMPANY_id</option>"; } echo "<option></option></select><br>"; echo "<table width=\"50%\"><tr>"; echo "<td align=\"center\" Class=\"TableRowTitle\" width=\"12.5%\">Serial No</td><td align=\"center\" Class=\"TableRowTitle\" width=\"12.5%\">Select</td></tr>"; $query1 = "SELECT * FROM products where jobid = '$row_ID' order by SERIALNO asc LIMIT 0 , 1000;"; $result1 = mysql_query($query1); $num_rows=mysql_num_rows($result1); while ($row=mysql_fetch_array($result1)) { $SERIALNO = $row['SERIALNO']; echo "<tr onMouseOver=\"this.bgColor = '#C0C0C0'\" onMouseOut =\"this.bgColor = '#EDEDED'\" bgcolor=\"#EDEDED\"> <td Class=TableRow8 width=\"12.5%\">$SERIALNO</td><td Class=TableRow8><input type=\"checkbox\" name=\"id[]\" value=\"$SERIALNO\"></td></tr>"; } echo "</table>"; $ADVICENOTE =$_POST['ADVICENOTE']; $SHIPDATE =$_POST['SHIPDATE']; $JOBID2 =$_POST['JOBID2']; //$COMPANY_ID =$_POST['COMPANY_ID']; if (!empty($_POST['id'])) { //echo "ROW_id = $row_ID<br>"; $query =("UPDATE products SET ADVICENOTE = '$ADVICENOTE' , SHIPDATE = '$SHIPDATE' , COMPANY_ID = '$COMPANY_id1' , JOBID = '$JOBID2' WHERE SERIALNO IN('" . implode("','",$_POST['id']) . "')"); //AND SERIALNO IN('" . implode("','",$_POST['id']) . "')"); //echo "$query<br>"; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); } ?> <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.myform.list)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.myform.list)"> <input type="submit" name="submit1" value="SAVE" Class="LoginButtons"> </form> </div> </body> </html>
-
Thanks for your help got it working the \\n Thanks again.
-
I have this bit of code which should do an alert popup which did work until i tried to put a line feed into it what am I doing wrong if ($linecount > 24) { echo "<script type=\"text/javascript\">alert('Hello\n How are you?')</script>"; } ?> Thanks
-
Force a file to a certain directory when downloading
rrayner replied to rrayner's topic in PHP Coding Help
Thanks -
I have the following code thanks to php.net which downloads a file from the server and I was wondering if you can force it to download into a certain directory? <?php $file = '317.txt'; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } ?> Thanks Rob.