Jump to content

witham

Members
  • Posts

    86
  • Joined

  • Last visited

    Never

Everything posted by witham

  1. Problem solved!! After much more digging and reading I managed to do this by including header('Content-Type: application/pdf'); at the very top of the script and to display the file // Display uploaded.pdf readfile($upfile); as the last function call. Thanks anyway I hope this helps someone else!!
  2. Thanks <html> <head> <title>Uploading...</title> </head> <body> <h1>Uploading file...</h1> <?php if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } // Does the file have the right MIME type? if ($_FILES['userfile']['type'] != 'application/pdf') { echo 'Problem: file is not pdf text'; exit; } // put the file where we'd like it $upfile = 'C:/uploads/'.$_FILES['userfile']['name']; if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $upfile)) { echo 'Problem: Could not move file to destination directory'; exit; } } else { echo 'Problem: Possible file upload attack. Filename: '; echo $_FILES['userfile']['name']; exit; } echo 'File uploaded successfully<br><br>'; // reformat the file contents $contents = strip_tags($contents); $fp = PDF_open_file($upfile, 'w'); fwrite($fp, $contents); ?> </body> </html>
  3. Hi thanks for your replay. All I really need to do is display the pdf in the browser after the upload.
  4. Hi I have written an upload script that restricts users from uploading anything other than pdf documents. After the php handles the upload and sends it to the directory I would really like to show a preview of the pdf that was uploaded. I have searched through the php.net website and have got really confused as to which pdf function to call. I assumed it would simply be PDF_open_file?? but I can't seem to get it to work. Before I continue it would be great to be certain that I am using the correct function. Thanks
  5. Thank you problem solved can't believe it was that simple.
  6. Hi I hope someone can help I have been searching the net for hours looking for a solution. I have mysql running through xampp on a laptop running windows vista. I also have the identical setup on a pc running xp which works perfectly. My issue is that whilst I can connect to phpmyadmin through localhost I cannot connect ant databases that have been imported from the xp setup. The error I get is below, I have tried to echo the Host and password ect but they don't appear? Could not connect to database server: \n"); // mysql_select_db selects a database to use on the database server //pointers to by $dblink // the @ sign before the command supresses any error messages @mysql_select_db ('weld' , $dblink) or die (" Could not connect to the database \n"); echo 'Host: '.$dbhost.' '; echo 'Username: '.$dbuser.' '; echo 'Password: '.$dbpass.' '; echo 'Database: '.$dbname; ?> Error Processing Query As the php works perfectly on xp setup I can't determine where the problem is??
  7. Just one more thing if I could ask how would I use an image as the link??
  8. Thanks very much its working now I had tried about every combination I could think of except that one.
  9. Thanks for you reply I have a database that contains various information input via a form this includes name, address and suchlike. Below is the array I want to display but I need the "compfile" to display as a hyperlink to the file. { // $row["fieldname" returns the content for the field in the current row echo "<tr><td>" .$row["MANNAME"]. "</td>"; echo "<td>" .$row["prodtype"]. "</td>"; echo "<td>" .$row["proddesc"]. "</td>"; echo "<td>" .$row["prodnar"]. "</td>"; echo "<td>" .$row["prodequiv"]."</td>"; echo "<td><a href=>" .$row["compfile"]."</td></tr>"; } // close html table tag echo "</table>\n";
  10. hi i am hoping someone can help me, I need to upload the path to a pdf file stored on the same machine. I have tried "file upload" but I can't seem to make it work. I will continue to try but I just need to establish if this is the correct piece of code to be using?
  11. Thanks very much for the assistance I have managed to connect.
  12. I hope someone can help I have set up xampp from apache friends on a laptop and written a php & mysql database which works fine. I loaded the same software, databases and php scripts onto another computer giving it the ip 192.168.0.5 but it will not connect: These are the variables I am using to try and connect: $dbuser = ''; // your database server user name $dbhost = '192.168.0.5'; // name of the sql server $dbpass = 'root'; // your database server password $dbname = 'weld'; // the name of the database to connect to and this is the mysql_connect and mysql_select_db // mysql_connect connects to the database server and returns a link to the the resource $dblink = @mysql_connect("$dbhost","$dbpass") or die("<p><b>Could not connect to database server: ($dbhost)</b></p>\n"); // mysql_select_db selects a database to use on the database server pointers to by $dblink // the @ sign before the command supresses any error messages @mysql_select_db ($dbname , $dblink) or die ("<p><b>Could not connect to database ($dbname)</b></p>\n");
  13. Hi I have a web application I am building and I would really like to navigate to a file so that this file path is subsequently rendered in a php script table as a link to the file. I have been reading alot about file upload but I don't think this is what I need as I only want to show the link where the file is and not actually upload it! This is the existing script: </select></td></tr> <tr><td class="style8">Product Name:</td> <td class="style8"><input type text name="ProdName"></td></tr> <tr><td class="style8">Product File Path:</td> [color=red]<td class="style8"><input type text name="FilePath"></td></tr>[/color] <tr><td class="style8">Product Equivalent:</td> <td><input type text name="ProdEquiv"></td></tr> The FilePath is the variable I want to pass to the script that handles the displaying of the link: { // $row["fieldname"] returns the content for the field in the current row echo "<tr><td>" .$row["MANNAME"]. "</td>"; echo "<td>" .$row["prodtype"]. "</td>"; echo "<td>" .$row["FilePath"]. "</td>"; echo "<td><a href=\"http://localhost/".$row["Compsheet"].".pdf\">".$row["Compsheet"]."</a></td>"; echo "<td>" .$row["prodequiv"]. "</td></tr>"; } // close html table tag echo "</table>\n"; I would be grateful if anyone could give me some assistance. Thanks
  14. Guys thats fantastic thanks for the help I appreciate it
  15. Hi I am hoping someone out there can help me with the final piece to a php script I am creating, let me explain. I have a page that allows users to query a database using two drop down boxes populated dynamically the page that processes the results of this query shows the data in a table. One of the columns of this table contains data which I really want to be links to files This is what I have presently but the link doesn't work when I click it?? // mysql_fetch_array fetches the results from the query a row at a time using a while loop each time it's called // the result is returned as an array that can be referenced either by field name or by it's index while ($row = mysql_fetch_array ($result)) // loop through the rows outputing them as html table rows { // $row["fieldname"] returns the content for the field in the current row echo "<tr><td>" .$row["MANNAME"]. "</td>"; echo "<td>" .$row["prodtype"]. "</td>"; echo "<td>" .$row["proddesc"]. "</td>"; echo "<td><a href>" .$row["Compsheet"]. "</td>"; echo "<td>" .$row["prodequiv"]. "</td></tr>"; } // close html table tag echo "</table>\n"; Thanks
  16. Thank you for your reply, I would really like the user to be able to view the pdf but everything I have read suggests that putting actual files into a database is not efficient as there could be alot? If the pdf could be embedded without compromising performance that would be fantastic
  17. I am sure this is possible but unsure exactly how to do it so let me explain. I would like to have a number of pdf files stored in a directory on the server. I would then like to include the paths to these files within a php array to output into an html table. Could anyone point me in the right direction please I have searched the forum and the net but nothing seems what I need?? I thought perhaps include() might help but before I go ahead I thought I'd ask for help.
  18. Thanks for the pointers for some really weird reason notepad (which I was using to edit the page source) wasn't showing the {} brackets. This is why I was a little vague and confused by the previous post!! All sorted now thanks again!!
  19. Thanks very much for the reply can I ask what you mean by the opening bracket, still can't see it (sorry)?? I don't know if errors are turned on how would I check this please? Could you tell me why the opening and closing brackets may be an issue?
  20. I would really appreciate a fresh pair of eyes looking at this code as it will not render properly it just displays the combobox at the bottom of the page. I have stared and stared had a break and stared and stared again but I cannot see the problem. I know it is something stupidly simply but "not seeing the wood for trees" springs to mind. <? //check the $ProdName variable to see if it has data if not send the user back to the entry page // this has to be done before any output $ProdName = $_GET['ProdName']; $ProdEquiv = $_GET['ProdEquiv']; $Manufacturer = $_GET['Manufacturer']; $ProdNar = $_GET['ProdNar']; $Category = $_GET['Category']; if (empty($ProdName)){ header("Location: addprod.php"); die ("opps"); } if (empty($ProdEquiv)){ header("Location: addprod.php"); die ("opps"); } $dbuser = 'test'; // your database server user name $dbhost = 'localhost'; // name of the sql server $dbpass = ''; // your database server password $dbname = 'weld'; // the name of the database to connect to // use a compare statement to check for duplicates $sqlCOMPARE = "SELECT * from prodname where '$ProdName' = proddesc;"; // the sql query to insert data into the prodname table $sqlINSERT = "INSERT into prodname values (null, '$Manufacturer', '$Category', '$ProdName', '$ProdNar', '$ProdEquiv');"; $sqlINSERT = strtoupper($sqlINSERT); //use to display the desired data $sqlSELECT $sqlSELECT = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv FROM man, produse, prodname where manno = manid and manid = '$Manufacturer' and useid = '$Category' and prodid = useid and manno = MANID and useid = USEID order by MANNAME;"; // mysql_connect connects to the database server and returns a link to the the resource $dblink = @mysql_connect("$dbhost","$dbuser","$dbpass") or die("<p><b>Could not connect to database server: ($dbhost)</b></p>\n"); // mysql_select_db selects a database to use on the database server pointers to by $dblink // the @ sign before the command supresses any error messages @mysql_select_db ($dbname , $dblink) or die ("<p><b>Could not connect to database ($dbname)</b></p>\n"); // now execute the next query to determine if a duplicate has been entered and use // an if statement to return the user to the entry page if this is true $result = mysql_query($sqlCOMPARE, $dblink) or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n"); if ( mysql_num_rows($result) > 0 ){ header("Location: alreadyin.php"); die ("opps"); // now execute the next query to update the database table $result = mysql_query($sqlINSERT, $dblink) or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n"); // now execute the next query to display these results $result = mysql_query($sqlSELECT, $dblink) or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n"); ?> <head> <title>W.E.L.D.</title> </head> <body> <? // output the table and the first row headings echo'<table align = "center" border=0>' . "\n"; echo'<tr><td colspan = 3 align = "center"><table width="100" border="0" cellspacing="10" cellpadding="10"> <tr> <th scope="row"><img src="car.jpg" width="150" height="150"></th> <td><img src="gears.jpg" width="150" height="150"></td> <td><img src="wheel.jpg" width="150" height="150"></td> <td><img src="metalworking.jpg" width="150" height="150"></td> </tr> </table></td></tr>'; echo '<table align = "center" border="1" cellspacing="2" cellpadding="2">' . "\n"; echo "<tr bgcolor = #000000><td>MANUFACTURER</td><td>PRODUCT TYPE</td><td>PRODUCT NAME</td><td>PRODUCT DESCRIPTION</td><td>PRODUCT EQUIVALENT</td></tr>\n"; // mysql_fetch_array fetches the results from the query a row at a time each time it's called // the result is returned as an array that can be referenced either by field name or by it's index while ($row = mysql_fetch_array ($result)) // loop through the rows outputing them as html table rows // $row["fieldname"] returns the content for the field in the current row echo "<tr'><td>" . $row["MANNAME"]. "</td>"; echo "<td>" . $row["prodtype"]. "</td>"; echo "<td>" . $row["proddesc"]. "</td>"; echo "<td>" . $row["prodnar"]. "</td>"; echo "<td>" . $row["prodequiv"]. "</td></tr>";} // close html table tag echo "</table>\n"; // the mysql_free_result command removes any resources relating to the query results // this happens automatically at the end of the script but still better to free up now mysql_free_result ($result); // the mysql_close command severs the link to the database, with scripts that make multiple // queries on the same database the command only needs to be done once after all queries are completed @mysql_close ($dblink) or die( "<p><b>Error while closing connection to database server:" . "($dbhost)</b></p>"); ?> <style type="text/css"> <!-- .combobox { background-color: #000000; color: #808080; font-size: 12pt; font-family: arial; font-weight: bold; } --> </style> <form> <table align=center border="0" width="80" cellspacing="0"> <tr><td width="100%" bgcolor="#000000"> <table border="0" width="100%" cellspacing="0" cellpadding="0"> </table> <!-- put in a link returning the user to the original page --> <table border="0" width="100%" cellspacing="0" cellpadding="3"> <tr><td width="2%"> <select class="combobox" name="SiteMap" onchange="if(options[selectedIndex].value){location = options[selectedIndex].value}" size="1"> <option value="">PLEASE CHOOSE AN OPTION</option> <option value="querydatabase.php">SEARCH BY MANUFACTURER & PRODUCT TYPE</option> <option value="addprod.php">ADD A PRODUCT</option> <option value="addman.php">ADD A MANUFACTURER</option> <option value="delprod.php">DELETE A PRODUCT</option> <option value="delman.php">DELETE A MANUFACTURER</option> <option value="searchweld.php">SEARCH FOR A PRODUCT BY NAME</option> <option value="amendprod.php">AMEND A PRODUCT</option> <option value="addcategory.php">ADD A CATEGORY</option> <option value="selectequiv.php">AMEND AN EQUIVALENT</option> </select> </body> </html>
  21. Thanks everyone for your help and examples, one question could I use mysql_affected_rows to identify the added row and change the background colour?
  22. Thanks very much for your post but won't this change the background of the whole table? I only want to change the colour of the added row
  23. I am hoping someone can point me in the right direction, I have a php script that adds a row to an sql database but I would like to change the background colour of the added row: <? //check the $ProdName variable to see if it has data if not send the user back to the entry page // this has to be done before any output $ProdName = $_GET['ProdName']; $ProdEquiv = $_GET['ProdEquiv']; $Manufacturer = $_GET['Manufacturer']; $ProdNar = $_GET['ProdNar']; $Category = $_GET['Category']; if (empty($ProdName)){ header("Location: addprod.php"); die ("opps"); } if (empty($ProdEquiv)){ header("Location: addprod.php"); die ("opps"); } $dbuser = 'user'; // your database server user name $dbhost = 'localhost'; // name of the sql server $dbpass = ''; // your database server password $dbname = 'ace; // the name of the database to connect to // use a compare statement to check for duplicates $sqlCOMPARE = "SELECT * from prodname where '$ProdName' = proddesc;"; // the sql query to insert data into the prodname table $sqlINSERT = "INSERT into prodname values (null, '$Manufacturer', '$Category', '$ProdName', '$ProdNar', '$ProdEquiv');"; $sqlINSERT = strtoupper($sqlINSERT); //use to display the desired data $sqlSELECT $sqlSELECT = "SELECT MANNAME, prodtype, proddesc, prodnar, prodequiv FROM man, produse, prodname where manno = manid and manid = '$Manufacturer' and useid = '$Category' and prodid = useid and manno = MANID and useid = USEID order by MANNAME;"; // mysql_connect connects to the database server and returns a link to the the resource $dblink = @mysql_connect("$dbhost","$dbuser","$dbpass") or die("<p><b>Could not connect to database server: ($dbhost)</b></p>\n"); // mysql_select_db selects a database to use on the database server pointers to by $dblink // the @ sign before the command supresses any error messages @mysql_select_db ($dbname , $dblink) or die ("<p><b>Could not connect to database ($dbname)</b></p>\n"); // now execute the next query to determine if a duplicate has been entered and use // an if statement to return the user to the entry page if this is true $result = mysql_query($sqlCOMPARE, $dblink) or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n"); if ( mysql_num_rows($result) > 0 ){ header("Location: alreadyin.php"); die ("opps"); } // now execute the next query to update the database table $result = mysql_query($sqlINSERT, $dblink) or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n"); // now execute the next query to display these results $result = mysql_query($sqlSELECT, $dblink) or die("<p>Error Processing Query</p><hr /><p>".mysql_error()."</p>\n"); ?> <style type="text/css"> tr {color: white; font-family: arial; font-weight: bold;} body { background: navy; background-image: url(); background-color: #333333; } .style2 {font-weight: bold; font-family: "arial", "Tempus Sans ITC", "Trebuchet MS";} .style3 {font-family: Arial, Helvetica, sans-serif} body,td,th { color: #999999; font-family: arial, Tempus Sans ITC, Trebuchet MS; } a:link { color: #666666; text-decoration: none; } a:visited { text-decoration: none; color: white; } a:hover { text-decoration: underline; } a:active { text-decoration: none; } a { font-family: arial, Times New Roman, Times, serif; color: #FFFFFF; } h1,h2,h3,h4,h5,h6 { font-family: arial; } .style5 {font-family: arial, "Times New Roman", Times, serif} .style7 {font-family: "arial", "Tempus Sans ITC", "Trebuchet MS"} </style> <head> <title>W.E.L.D.</title> </head> <!-- set the css format for the page--> <body> <? // output the table and the first row headings echo'<table align = "center" border=0>' . "\n"; echo'<tr><td colspan = 3 align = "center"><table width="100" border="0" cellspacing="10" cellpadding="10"> <tr> <th scope="row"><img src="car.jpg" width="150" height="150"></th> <td><img src="gears.jpg" width="150" height="150"></td> <td><img src="wheel.jpg" width="150" height="150"></td> <td><img src="metalworking.jpg" width="150" height="150"></td> </tr> </table></td></tr>'; echo '<table align = "center" border="1" cellspacing="2" cellpadding="2">' . "\n"; echo "<tr bgcolor = #000000><td>MANUFACTURER</td><td>PRODUCT TYPE</td><td>PRODUCT NAME</td><td>PRODUCT DESCRIPTION</td><td>PRODUCT EQUIVALENT</td></tr>\n"; // mysql_fetch_array fetches the results from the query a row at a time each time it's called // the result is returned as an array that can be referenced either by field name or by it's index while ($row = mysql_fetch_array ($result)) // loop through the rows outputing them as html table rows { // $row["fieldname"] returns the content for the field in the current row echo "<tr><td>" . $row["MANNAME"]. "</td>"; echo "<td>" . $row["prodtype"]. "</td>"; echo "<td>" . $row["proddesc"]. "</td>"; echo "<td>" . $row["prodnar"]. "</td>"; echo "<td>QUALUBE " . $row["prodequiv"]. "</td></tr>"; } // close html table tag echo "</table>\n"; // the mysql_free_result command removes any resources relating to the query results // this happens automatically at the end of the script but still better to free up now mysql_free_result ($result); // the mysql_close command severs the link to the database, with scripts that make multiple // queries on the same database the command only needs to be done once after all queries are completed @mysql_close ($dblink) or die( "<p><b>Error while closing connection to database server:" . "($dbhost)</b></p>"); ?> It is a while since my php college course and I would really appreciate some help Thanks
  24. Thanks for your reply, I missed the database name previously which I have now put in but I still get the message. I also read the link you kindly put up and to be honest being new to php I am not really any wiser as I want to put the data into an database and this explains putting it into a file?
  25. Hi I am trying o uploa some files into mysql database by keep getting the error message Warning: fread(): supplied argument is not a valid stream resource in C:\Program Files\xampp\htdocs\upload.php on line 4 File ID: 0 File Name: File Size: File Type: To upload another file Click Here I have an html form <form method="post" action="upload.php" enctype="multipart/form-data"> Description:<br> <input type="text" name="form_description" size="40"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000000"> <br>File to upload:<br> <input type="file" name="form_data" size="40"> <p><input type="submit" name="submit" value="submit"> </form> and a php handling script <?php mysql_connect("localhost","root",""); mysql_select_db("database_name"); $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); $result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); $id= mysql_insert_id(); print "<p>File ID: <b>$id</b><br>"; print "<p>File Name: <b>$form_data_name</b><br>"; print "<p>File Size: <b>$form_data_size</b><br>"; print "<p>File Type: <b>$form_data_type</b><p>"; print "To upload another file <a href=http://localhost/upload.html> Click Here</a>"; ?> I have been through the code and seached the forum but can't find a resolution so I would really appreciate some help!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.