The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
vBulletin 4 Request - Little help wrapping some PHP with my page style.
I need your help.
Ive been trying to wrap the below code with my sites header, footer, style but I keep getting errors. The code below works on the forum root. The page is called cpg_index.php. Any help would be great. Thanks. Code:
<?php $delta = 24; $reduce_brightness = true; $reduce_gradients = true; $num_results = 20; include_once("colors.inc.php"); $ex=new GetMostCommonColors(); $colors=$ex->Get_Color("test.jpg", $num_results, $reduce_brightness, $reduce_gradients, $delta); ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Image Color Extraction</title> <style type="text/css"> * {margin: 0; padding: 0} body {text-align: center;} form, div#wrap {margin: 10px auto; text-align: left; position: relative; width: 500px;} fieldset {padding: 20px; border: solid #999 2px;} img {width: 200px;} table {border: solid #000 1px; border-collapse: collapse;} td {border: solid #000 1px; padding: 2px 5px; white-space: nowrap;} br {width: 100%; height: 1px; clear: both; } </style> </head> <body> <div id="wrap"> <form action="#" method="post" enctype="multipart/form-data"> <fieldset> <legend>Upload Your Own Image</legend> <input type="file" name="imgFile" /> <input type="submit" name="action" value="Process" /> </fieldset> </form> <?php // was any file uploaded? if ( isset( $_FILES['imgFile']['tmp_name'] ) && strlen( $_FILES['imgFile']['tmp_name'] ) > 0 ) { // move image to a writable directory if (! move_uploaded_file($_FILES['imgFile']['tmp_name'], 'images/'.$_FILES['imgFile']['name'])) { die("Error moving uploaded file to images directory"); } $colors=$ex->Get_Color( 'images/'.$_FILES['imgFile']['name'], $num_results, $reduce_brightness, $reduce_gradients, $delta); ?> <table> <tr><td>Color</td><td>Color Code</td><td>Percentage</td><td rowspan="<?php echo (($num_results > 0)?($num_results+1):22500);?>"><img src="<?='images/'.$_FILES['imgFile']['name']?>" alt="test image" /></td></tr> <?php foreach ( $colors as $hex => $count ) { if ( $count > 0 ) { echo "<tr><td style=\"background-color:#".$hex.";\"></td><td>".$hex."</td><td>$count</td></tr>"; } } ?> </table> <br /> <?php } ?> </div> </body> </html> |
#2
|
|||
|
|||
What error are you receiving?
P.S. Just a heads up that the script you posted is vulnerable to arbitrary file upload, anyone can upload any kind of file to your server, including backdoors which can take over your server and interact with your database in any kind of way you can imagine. |
#3
|
||||
|
||||
That sucks. Any way to limit the file types to just images?
--------------- Added [DATE]1500750280[/DATE] at [TIME]1500750280[/TIME] --------------- Well I just tried to upload other file types and all I got was ton of errors. I checked the upload folder and nothing but images. Still Im sure your right and there is a way but maybe if the form was wrapped in a condition to only show to members that would cut down some of the risk. Maybe a captia also... --------------- Added [DATE]1500750798[/DATE] at [TIME]1500750798[/TIME] --------------- And just a thought. Can the code above be tweaked to use on a CMS PSP Page? Ive never tried to use PHP that way I always use it on an external page. Again thanks for the help. |
#4
|
||||
|
||||
|
#5
|
||||
|
||||
Quote:
Thanks Mark thats actually what Ive been trying to do. Still getting errors. |
#6
|
||||
|
||||
I've used the method described in that article many times to create custom pages which include the header/footer and it has always worked very well for me.
|
#7
|
||||
|
||||
Ive used that method just fine if Im only adding simply html but the trick is getting the PHP to work. Still stuck. Anyone?
|
#8
|
||||
|
||||
I generally put the php in the external script, and then have the HTML rendered using a custom template. For example, in my "Profile Reporter" product, I use the following external script to render the custom page:
PHP Code:
HTML Code:
{vb:stylevar htmldoctype} <html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html"> <head> <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title> <vb:if condition="$vboptions['storecssasfile']"> {vb:cssfile forumhome-rollup.css} <vb:else /> {vb:cssfile forumbits.css,forumhome.css,options.css} </vb:if> {vb:raw headinclude} {vb:raw headinclude_bottom} <style type="text/css"> #report_profile form { margin-bottom: 2.5em; } .wgo_block { border: {vb:stylevar formrow_border}; } #rpform { padding: 5px; margin-bottom: 1em; } #rpform fieldset { border: {vb:stylevar formrow_border}; padding: 5px; } #rpform fieldset:first-of-type { display: inline-block; width: 25%; } #rpform fieldset:last-of-type { float: right; width: 70%; } #rpform fieldset div { display: inline-block; min-height: 16px; } #rpform fieldset div::after { content: ":"; } #rpform fieldset input { float: right; margin-top: 2px; } legend::before { content: "\00a0"; } legend::after { content: ":\00a0"; } textarea { resize: none; height: {vb:raw text_height}px; width: 100%; font-size: 14px; font-family: Arial; } #fbuttons { float: right; margin-top: 10px; } #fbuttons input { cursor: pointer; } #explain { padding: 5px; text-align: justify; } </style> <script> function checkEmpty() { if (!({vb:raw rp_condition})) { return 0; } else if (document.getElementsByName("other")[0].checked && !document.getElementsByName("comment")[0].value) { return 1; } else { return 2; } } </script> </head> <body> {vb:raw header} {vb:raw navbar} <div id="report_profile" class="wgo_block"> <h2 class="blockhead"> {vb:rawphrase markfl_rp_header, {vb:raw reportedusername}} </h2> <form name="reportprofile_form" method="post" action="reportprofilethread.php"> <input type="hidden" name="url" value="{vb:raw $_SERVER['HTTP_REFERER']}" /> <input type="hidden" name="reporteduser" value="{vb:raw reportedusername}" /> <input type="hidden" name="reporteruserid" value="{vb:raw reporteruserid}" /> <input type="hidden" name="reporteduserid" value="{vb:raw reporteduserid}" /> <div id="rpform"> <fieldset> <legend>{vb:rawphrase markl_rp_legendreasons}</legend> {vb:raw rp_checkboxes} </fieldset> <fieldset> <legend>{vb:rawphrase markl_rp_legendcomments}</legend> <textarea name="comment"></textarea> </fieldset> <div id="fbuttons"> <input title="{vb:rawphrase markfl_rp_formresettitle}" class="button" type="reset" name="rpreset" value="{vb:rawphrase markfl_rp_formreset}" /> <input title="{vb:rawphrase markfl_rp_form_submittitle}" class="button" type="submit" name="rpsubmit" value="{vb:rawphrase markfl_rp_form_submit}" onclick="var state = checkEmpty(); if (state == 0){alert('{vb:rawphrase markfl_rp_form_submitemptyalert}'); return false;} else if (state == 1) {alert('{vb:rawphrase markfl_rp_form_submitotheralert}'); return false;}" /> </div> </div> </form> <div id="explain"> {vb:rawphrase markfl_rp_formexplain} </div> </div> {vb:raw footer} </body> </html> |
#9
|
||||
|
||||
Ive been trying that but the multiple instances of opened and closed PHP are screwing me up. I either get Global.php errors or just the form shows up with no formatting.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|