Quantcast
Channel: PHP Freaks: PHP Help
Viewing all 13200 articles
Browse latest View live

PHP File Deletion Problem

$
0
0

Hi everyone,
 
Lately, in a school project I've been working on, which involves using XML files to save information and read it out, as well as dynamically create and delete themselves. It's all been working just fine, until quite recently (today) when I noticed that two XML files had not deleted themselves, like they were supposed to. I went in and deleted them manually, but now they will display themselves whenever I try to display a different XML file with the same identification. Here's my XML file template that they copy from:

<?xml version="1.0" encoding="ISO-8859-1"?>
<msg>
	<to>template</to>
	<toid>0</toid>
	<from>template</from>
	<fromid>0</fromid>
	<title>template</title>
	<text>template</text>
	<archived>false</archived>
	<replyto>N/A</replyto>
	<id>0</id>
</msg>

And here's my display code (Whole webpage in this case):

<!DOCTYPE HTML>
<html>
	<script src="xml.js"></script>
	<script>
		function loadmsg() {
			m = document.getElementById("messageid");
			f = document.getElementById("from");
			t = document.getElementById("title");
			tt = document.getElementById("text");
			p = document.getElementById("everything");
			if (m.innerHTML != "") {
				if (localStorage.name == loadXMLDoc("msg"+m.innerHTML+".xml").getElementsByTagName("to")[0].childNodes[0].nodeValue) {
					p.removeChild(document.getElementById("msgloadthing"));
					x = loadXMLDoc("msg"+m.innerHTML+".xml");
					f.innerHTML = x.getElementsByTagName("from")[0].childNodes[0].nodeValue;
					t.innerHTML = x.getElementsByTagName("title")[0].childNodes[0].nodeValue;
					tt.innerHTML = x.getElementsByTagName("text")[0].childNodes[0].nodeValue;
				}
				else {
					
				}
			}
			else if (m.innerHTML == "") {
				
			}
			m.innerHTML = "";
		}
	</script>
	<noscript>
		
	</noscript>
	<head>
		<link rel="stylesheet" type="text/css" href="main.css"/>
		<title>Messages</title>
	</head>
	<body>
		<div id="everything">
		<script src="header.js"></script>
			<div id="header">
				Database Testing
			</div>
			<div id="sidebar">
				<a href="index.php">Home</a><br/>
				<a href="login.php">Login</a><br/>
				<a href="create.php">Create an Account</a><br/>
				<a href="userhome.php">User Home</a><br/>
			</div>
			<div id="msgloadthing">
				<?php
					echo "<em>If messages aren't appearing, try logging back in.";
					//load all messages that the current user has access to
					$num = 1;
					$class = false;
					while (file_exists("msg".$num.".xml")) {
						$sxe = new DOMDocument('1.0', 'utf-8');
						$sxe->formatOutput = true;
						$sxe->preserveWhiteSpace = false;
						$sxe->load("msg".$num.".xml");
						$msg = $sxe->getElementsByTagName("msg")->item(0);
						$from = $msg->getElementsByTagName("from")->item(0)->nodeValue;
						$title = $msg->getElementsByTagName("title")->item(0)->nodeValue;
						$to = $msg->getElementsByTagName("to")->item(0)->nodeValue;
						$fromid = $msg->getElementsByTagName("fromid")->item(0)->nodeValue;
						if ($_COOKIE["username"] == $to) {
							if ($class == false) {
								echo "<div class='t1'><a href='user.php?id=".$fromid."'>".$from."</a> - <a href='messages.php?id=".$num."'>".$title."</a></div>";
								$class = true;
							}
							else if ($class == true) {
								echo "<div class='t2'><a href='user.php?id=".$fromid."'>".$from."</a> - <a href='messages.php?id=".$num."'>".$title."</a></div>";
								$class = false;
							}
						}
						$num = $num + 1;
					}
				?>
			</div>
			<div id="messagecontent">
				<?php
				if (!(file_exists("msg".$_GET["id"].".xml")) and $_GET["id"] != "") {
					echo "<em><strong>ERROR: Message does not exist.</strong></em>";
				}
				if ($_GET["id"] != "") {
					echo '<div id="messageid">'.$_GET["id"].'</div>';
					echo "<a href='deletemsg.php?id=".$_GET["id"]."'>Delete</a>";
				}
				else {
					echo '<div id="messageid">'.$_GET["id"].'</div>';
				}
				?>
				<script>
					if (document.getElementById("messageid").innerHTML != "") {
						m = loadXMLDoc("msg"+document.getElementById("messageid").innerHTML+".xml");
						document.write("<a href='user.php?id="+m.getElementsByTagName("fromid")[0].childNodes[0].nodeValue+"'><div id='from'></div></a>");
					}
				</script>
				<div id="title"></div>
				<div id="text"></div>
				<script>
					loadmsg();
				</script>
			</div>
			<div id="footer">
				<em>© 2013 [Redacted]</em>
			</div>
		</div>
	</body>
</html>

And the creation code:
 

<!DOCTYPE HTML>
<html>
	<script>
		//JS code goes here
	</script>
	<noscript>
		
	</noscript>
	<head>
		<link rel="stylesheet" type="text/css" href="main.css"/>
		<title>Send Message</title>
	</head>
	<body>
		<div id="everything">
		<script src="header.js"></script>
			<div id="header">
				Database Testing
			</div>
			<div id="sidebar">
				<a href="index.php">Home</a><br/>
				<a href="login.php">Login</a><br/>
				<a href="create.php">Create an Account</a><br/>
				<a href="userhome.php">User Home</a><br/>
				
			</div>
			<div id="content">	
				<?php
					$num=1;
					$num1 = 1;
					while (file_exists("msg" . $num . ".xml") == 1) {
						if (file_exists("msg" . $num . ".xml") == 1) {
							$num = $num + 1;
						}
					}
					/*if (file_exists("msg" . $num . ".xml") == 0) {
						$num = $num - 1;
					}*/
					copy("template.xml", "msg".$num.".xml");
					while (file_exists("user".$num1.".xml")) {
						$usrr = new DOMDocument('1.0', 'utf-8');
						$usrr->formatOutput = true;
						$usrr->preserveWhiteSpace = false;
						$usrr->load("user".$num1.".xml");
						$usr = $usrr->getElementsByTagName("user")->item(0);
						$name = $usr->getElementsByTagName("name")->item(0);
						if ($name->nodeValue == $_COOKIE["username"]) {
							$ffrom = $usrr->getElementsByTagName("id")->item(0);
							break;
						}
						$num1 = $num1 + 1;
					}
					$usrrr = new DOMDocument('1.0', 'utf-8');
					$usrrr->formatOutput = true;
					$usrrr->preserveWhiteSpace = false;
					$usrrr->load("user".$_COOKIE["id"].".xml");
					$nusr = $usrrr->getElementsByTagName("user")->item(0);
					$tto = $nusr->getElementsByTagName("name")->item(0);
					
					$sxe = new DOMDocument('1.0', 'utf-8');
					$sxe->formatOutput = true;
					$sxe->preserveWhiteSpace = false;
					$sxe->load("msg".$num.".xml");
					$msg = $sxe->getElementsByTagName("msg")->item(0);
					$to = $msg->getElementsByTagName("to")->item(0);
					$toid = $msg->getElementsByTagName("toid")->item(0);
					$from = $msg->getElementsByTagName("from")->item(0);
					$fromid = $msg->getElementsByTagName("fromid")->item(0);
					$title = $msg->getElementsByTagName("title")->item(0);
					$text = $msg->getElementsByTagName("text")->item(0);
					$id = $msg->getElementsByTagName("id")->item(0);
					$to->nodeValue = $tto->nodeValue;
					$toid->nodeValue = $_COOKIE["id"];
					$from->nodeValue = $_COOKIE["username"];
					$fromid->nodeValue = $ffrom->nodeValue;
					$title->nodeValue = $_POST["title"];
					$text->nodeValue = $_POST["text"];
					$id->nodeValue = $num;
					$sxe->save("msg".$num.".xml");
					echo "<em>Message sent successfully.</em>";
				?>
				<form action="userhome.php">
					<input type="submit" value="Continue"/>
				</form>
			</div>
			<div id="footer">
				<em>© 2013 [Redacted]</em>
			</div>
		</div>
	</body>
</html>

And last, but not least, the deletion code:

<?php
	header("Location: messages.php?id=");
	unlink("msg".$_GET["id"].".xml");
	exit;
?>

I'm fully aware that the website is not built in the best way, so over the summer I'm planning on fixing a lot of it. I just can't seem to figure this out though. Thanks!


Syntax error, unexpected ')'

$
0
0
$options = array(
    'title' => __( 'Slider', 'yit' ),
    'options' => array( '' => __( 'Default', 'yit' ), 'none' => __( 'None', 'yit' ) ) + yit_get_sliders(),
    'desc' =>  __( 'Select the slider that you want to use in the page.', 'yit' ),
);
yit_add_option_metabox( 'yit-page-settings', __( 'Header', 'yit' ), '_slider_name', 'select', $options );    


yit_metaboxes_sep( 'yit-page-settings', __( 'Header', 'yit' ) );


$options = array(
    'title' => __( 'Use static image', 'yit' ),
    'desc'  =>  __( 'Set YES if you want a static header, instead of the slider.', 'yit' ),
    'std'   => 0
);
yit_add_option_metabox( 'yit-page-settings', __( 'Header', 'yit' ), '_use_static_image', 'onoff', $options );


$options = array(
    'title' => __( 'Static image', 'yit' ),
    'desc'  =>  __( 'Upload here the image to use for the static header, only if you have set to YES the option above.', 'yit' ),
    'std'   => ''
);
yit_add_option_metabox( 'yit-page-settings', __( 'Header', 'yit' ), '_static_image', 'upload', $options ); 


$options = array(
    'title' => __( 'Static image Link', 'yit' ),
    'desc'  =>  __( 'The URL where the fixed image will link.', 'yit' ),
    'std'   => ''
);
);
yit_add_option_metabox( 'yit-page-settings', __( 'Header', 'yit' ), '_static_image_link', 'text', $options ); 


$options = array(
    'title' => __( 'Static image target', 'yit' ),
    'desc' =>  __( 'How to open the link of the static image.', 'yit' ),
    'options' => array(                 
        '_self' => __( 'Default', 'yit' ),    
        '_parent' => __( 'Parent frameset', 'yit' ),
        '_top' => __( 'Full body of the window', 'yit' ),
        '_blank' => __( 'In a new window', 'yit' ),
    ),
);
yit_add_option_metabox( 'yit-page-settings', __( 'Header', 'yit' ), '_static_image_target', 'select', $options ); 

Not sure what is wrong with it as far as I can see. Anyone got an idea?

Unsure on how to set cookies in my php code so my jquery style change is permanent.

$
0
0

I have a table displaying database data and there's a "Dead" button next to each row for users to click when the information in that row is dead. When the button is clicked the info in the row is crossed out. Now this works, but the change isnt permanent. When I refresh the page, the row is no longer crossed out. I think I have to set cookies.. ? but I am unsure on how to do this. Are there any tutorials or something I can watch on this. Just looking at http://php.net/manual/en/function.setcookie.php is not helping. I'm reading it and my brain is like.. what?!?! How do I apply that to what I want to do?

 

Here's my code

php

<?php while($row = $data->fetch_assoc()) { ?>
<tr>

<td><?php echo $row['title']; ?> </td>
<td><?php echo  $row['requester']; ?></td>
<td><?php echo $row['reward']; ?></td>
<td><?php echo $row['qual']; ?></td>
<td><?php echo $row['time']; ?></td>
<td><?php echo $row['category']; ?></td>
<td><a href="<?php $row['link']; ?>"><button class="btn btn-mini btn-primary" type="button">Do This Hit</button></a></td>
<td><button class="btn btn-danger btn-mini dead" type="button">Dead</button></td>

</tr>
<?php } ?>

and here's my javascript

$('table').on('click','.dead',function(){
	
	
          $(this).parent().siblings().css({textDecoration: 'line-through'});
    });
    

I'm just totally stuck right now, so any help is appreciated. Also, if cookies arent the way to go, please feel free to suggest other ways.

 

Thanks.

struggling to come up with a way to do this

$
0
0

Weight and food diary. 

 

2 input forms to insert weight and then for one to insert what they had to eat. 

 

i then wanting it to show on a calendar, 

<?php
  /**
   * Account
   *
   * @package Digital Downloads Pro
   * @author wojoscripts.com
   * @copyright 2010
   * @version $Id: account.php, v2.00 2011-07-10 10:12:05 gewa Exp $
   */
  define("_VALID_PHP", true);
  require_once("init.php");
  
  if (!$user->logged_in)
      redirect_to("login.php");


?> 
 
 <?php include("header.php");?> 
 
 
  <!-- ============= CONTENT AREA STARTS HERE ============== -->
        		<div id="content">
                
                		<!-- SLIDER STARTS HERE -->
						<div id="slider" class="slider2">
								<div >
										
								</div>
						  <h2 class="slider-head">Track your Weight</h2><br /><br />
						  <div id="whats-hot" > <p></p>

									</div>	<br /><br /><br />

	
			                <!-- end of news div --><!-- end of container div -->
 <div class="w-pet-border"> 
  <br /><br />
  
        <table style='background-color:E1E1E1; color:000000;font-family: Verdana; font-size: 7pt;'><tr><td colspan='8' align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='3' color='000'><b>May 2013</b></font></td></tr><tr><tr><td align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='2' color='000'><b>Sun</b></font></td><td align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='2' color='000'><b>Mon</b></font></td><td align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='2' color='000'><b>Tue</b></font></td><td align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='2' color='000'><b>Wed</b></font></td><td align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='2' color='000'><b>Thu</b></font></td><td align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='2' color='000'><b>Fri</b></font></td><td align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='2' color='000'><b>Sat</b></font></td><td align='center' style='background-color:9999cc; color:000000;'><font face='Verdana' size='2' color='000'><b>Weekly</b></font></td></tr><td style="background-color:ccccff; color:000000; width:75;height:100"> </td><td style="background-color:ccccff; color:000000; width:75;height:100"> </td><td style="background-color:ccccff; color:000000; width:75;height:100"> </td><td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>1<br>
              Breakfast <br />
Lunch<br />
Tea<br />
Other<br />
Weight<br/>Creon</td><td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>2<br>  <br></td><td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>3<br>  <br></td><td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>4<br>  <br></td><td align='left' valign='top' style='background-color:ffffcc; color:000000;' width='91' height='100'>  <br><br>
          Creon:  0<br />
Best Weight: 0<br />
lowest Weight: 0</td></tr><tr>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>5</td>
<td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>6</td>
<td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>7</td>
<td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>8</td>
<td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>9<br>  <br></td><td align='left' valign='top' style='background-color:ffffff; color:000000;' width='75' height='100'><p>10<br>
</p></td><td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>11<br>  <br></td><td align='left' valign='top' style='background-color:ffffcc; color:000000;' width='91' height='100'>  <br><br>
        Creon:  0<br>
        Best Weight: 0<br>
        lowest Weight: 0<br></td></tr><tr>
          <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>12</td>
          <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>13</td>
          <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>14</td>
          <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>15</td>
          <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>16</td>
          <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>17</td>
          <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>18</td><td align='left' valign='top' style='background-color:ffffcc; color:000000;' width='91' height='100'>  <br><br>
            Creon:  0<br />
Best Weight: 0<br />
lowest Weight: 0</td></tr><tr>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>19</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>20</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>21</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>22</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>23</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>24</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='75'>25</td><td align='left' valign='top' style='background-color:ffffcc; color:000000;' width='91' height='100'>  <br><br>
    Creon:  0<br />
Best Weight: 0<br />
lowest Weight: 0</td></tr><tr>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='93'>26</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='93'>27</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='93'>28</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='93'>29</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='93'>30</td>
  <td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='93'>31</td><td align='left' valign='top' style='background-color:ccccff; color:000000;' width='75' height='93'>  <br><br> <br> </td><td align='left' valign='top' style='background-color:ffffcc; color:000000;' width='91' height='93'>  <br>
      <br>
      Creon:  0<br />
      Best Weight: 0<br />
      lowest Weight: 0</td></tr></table>



 </div><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />

	
 Beta v2.0
 <?php include("footer.php");?> 

this is the weight database

 

id date day month year username weight_lb weight_kg notes email

 

this is the my_food database

 

id username date day month year meal content notes creon

 

open a new page where they can see the content they added of the meals ie, breakfast, lunch etc. and to total the creon intake up from that week... 

 

 

if anyone could help me.. please i need to get it all working within this month. due to my article is being published in the CF Trust magazine and they want all my website to be full functional 

This is basic stuff, but..(multidimensional array count)

$
0
0

Hi,

 

I'm trying to figure out the following. I know it must need a nested loop, I just can't figure out quite the way to do it, so any help would be superb.

 

My MySQL db has a list of incidents that a servicedesk team take in any given month. It outputs, among others, incident_number, logged_by and resolved_by.  The logged_by is, of course, an individual member of the servicedesk. That person MAY resolve the incident himself, so he MAY appear in the resolved_by field too.

My aim is to get the following:

 

SD member 1, calls logged, calls resolved.

SD member 2, calls logged, calls resolved.

etc

 

Can someone help, please?

List numbers up to an assigned value.

$
0
0

OK, I know the topic title doesn't say much, but what I'm trying to do is fairly simple to explain.  What I'm trying to do is to have real time inventory of specific items that are listed in my database.  For simplicity, I'll just say that I have a two mysql query results that are identified in variables $total, and $used.  By subtracting $used from $total, I get the number of items still available ($available).  What I need to do is create a dropdown box that has numbers listed up to whatever amount is available. 

 

For example, if $available = 4, I need a dropdown box that has options 1,2,3, and 4. 

 

Any ideas on how to do this or what I should search for?  I have found nothing so far.  Thanks in advance for your help.

Need help with searching Categories

$
0
0

Hi - I am struggling to find a solution to a category problem.  

 
Perhaps I am over thinking this. I need to display a navigation menu in tabs so that as you tab through the hierarchy you can see the categories in the hierarchy both above and below where you currently are. 

 

 

Conceptually I found an architectural solution on Sitepoint called, Modified Preorder Tree Traversal - but it is quite complex and I was hoping for something a little easier. 

 

In simple terms I need to be able to search and display all the categories and sub categories going up or down the category hierarchy. It could be as much as 5 levels deep. 

 

My need is 3 fold: 

 

1 - starting at the root I have to find all the descendants. 

2 - if you start at the bottom of the hierarchy, I need to find all the ancestors. 

3 - Worst of all ... if you start half way down the hierarchy, I need to display both all the ancestors and all the descendants. 

 

Does anyone have some advice or resources I should consider ?? 

 

MANY MANY  Thanks ! 

 

 

 

 

Database connection failed: ... No such host is known.

$
0
0

( ! ) SCREAM: Error suppression ignored for

 

( ! ) Warning: mysql_connect(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\wamp\www\widget_corp\includes\connection.php on line 4

 

 

Database connection failed: php_network_getaddresses: getaddrinfo failed: No such host is known.

 

 

 

I am getting the error. I'm doing the PHP essential training course on Lynda.com. The teacher asked to make a constant.php file and then use constants to store the db user pass etc and then call it via the constant name or whatever and now i'm getting that huge error. I've been stuck for 2 days. Please help.


Is this poor coding?

$
0
0

I want my wordpress site running smoothly and I heard that poor coding can slow it down. The code I've put in sidebar-page.php is <div class="bgsidebar"> under the php code.

<div id="sidebar" class="col-right">

	<?php dynamic_sidebar('sidebar-page'); ?>		           
    
</div><!-- /#sidebar -->
<div class="bgsidebar"></div>

If this isnt a good idea could somebody help me out on this. I'd really appreciate it. Thank you

php form, only require if another field is filled..

$
0
0

ok, after hours trying to figure this out myself, I thought it was about time I joined a php community anyway. :)

 

I built a html web form.  It uses a php script to check for required fields and send the e-mail if it passes.  Just checking for a single field is filled, or not, is pretty straightforward and works like this..

  if(empty($dob)) {
    $error_message .= 'Error: dob required';
  }
  if(empty($dayphone)) {
    $error_message .= 'Error: day phone required';
  }

But I have a couple situations in the form where I need to only require another field if another field (or radio) is filled.

 

There's a field for Mobile Phone.  Under that I have two radio buttons that answer Allow Texts?  yes/no

<label for="mobphone"> Mobile Phone: </label> <input type="text" name="mobphone" id="fields"><br> 
				</div>
                <div id="form-radio">
                <label for="texts"> Allow Texts? </label>
                	<input type="radio" name="texts" value="yes">Yes
			<input type="radio" name="texts" value="no">No
		</div>

This was my best try...

   if(isset($mobphone) && empty($texts)) {
    $error_message .= 'Error: Allow Texts yes or no required';
  }

... and now, you probably know my level of php experience.   :blink:  ..I'm learning. lol

 

Am I on the right track?  Is it possible to do this?  a Better way?

 

The other fields with the same scenario are similar,.. they aren't radio buttons.  They are drop down or text fields.

 

Thanks for any help in advance!

 

~Joe

 

 

Undefined index: error in C:\wamp\www\tourprice.php on line 32

$
0
0

Can someone please  help > im new to php and trying to complete code for  a tour price calculator and keep getting the following error message

 

 Undefined index: error in C:\wamp\www\tourprice.php on line 32

 

line 32 reads

 

32   if ($_GET['error'] == "notnumeric"){

 33      echo "<p class=\"error\">*** Error! One or more fields was left blank or contained a non-numeric character.</p>";
34     }
 ?>

 

any help would be greatly appreciated

Changing metadata in an photo.

$
0
0

In a previous post I explained a problem I was having extracting metadata from a photo and then adding it back after resizing the photo.

I managed to solve that problem but have since discovered another issue.

 

When I resize the image the exif data written back to it contains the original size and what I need to store is the new size - but I am now completely lost as to how to go about doing this.

 

The command to extract the data from the image before resizing is

 

$exif_data = get_EXIF_JPEG( $filename );

 

The function 'get_EXIF_JPEG' is not a standard PHP function, but one contained in a separate file (EXIF.php) called as an 'include' in the resizing script.

However I assume that the information is called into an array because a later instruction

 

put_EXIF_JPEG( $exif_data, $jpeg_header_data );

 

writes it 'as is' back to the new image.

 

How can I :

- determine the structure/content of the array

- alter some of the content (ie the size information)

before writing it back to the new image.

 

 

Any and all assistance appreciated.

 

This is the function 'get_EXIF_JPEG' from the included script:


function get_EXIF_JPEG( $filename )
{
        // Change: Added as of version 1.11
        // Check if a wrapper is being used - these are not currently supported (see notes at top of file)
        if ( ( stristr ( $filename, "http://" ) != FALSE ) || ( stristr ( $filename, "ftp://" ) != FALSE ) )
        {
                // A HTTP or FTP wrapper is being used - show a warning and abort
                echo "HTTP and FTP wrappers are currently not supported with EXIF - See EXIF functionality documentation - a local file must be specified<br>";
                echo "To work on an internet file, copy it locally to start with:<br><br>\n";
                echo "\$newfilename = tempnam ( \$dir, \"tmpexif\" );<br>\n";
                echo "copy ( \"http://whatever.com\", \$newfilename );<br><br>\n";
                return FALSE;
        }

        // get the JPEG headers
        $jpeg_header_data = get_jpeg_header_data( $filename );


        // Flag that an EXIF segment has not been found yet
        $EXIF_Location = -1;

        //Cycle through the header segments
        for( $i = 0; $i < count( $jpeg_header_data ); $i++ )
        {
                // If we find an APP1 header,
                if ( strcmp ( $jpeg_header_data[$i]['SegName'], "APP1" ) == 0 )
                {
                        // And if it has the EXIF label,
                        if ( ( strncmp ( $jpeg_header_data[$i]['SegData'], "Exif\x00\x00", 6) == 0 ) ||
                             ( strncmp ( $jpeg_header_data[$i]['SegData'], "Exif\x00\xFF", 6) == 0 ) )          // For some reason, some files have a faulty EXIF name which has a 0xFF in it
                        {
                                // Save the location of the EXIF segment
                                $EXIF_Location = $i;
                        }
                }

        }

        // Check if an EXIF segment was found
        if ( $EXIF_Location == -1 )
        {
                // Couldn't find any EXIF block to decode
                return FALSE;
        }

        $filehnd = @fopen($filename, 'rb');

        // Check if the file opened successfully
        if ( ! $filehnd  )
        {
                // Could't open the file - exit
                echo "<p>Could not open file $filename</p>\n";
                return FALSE;
        }

        fseek( $filehnd, $jpeg_header_data[$EXIF_Location]['SegDataStart'] + 6  );

        // Decode the Exif segment into an array and return it
        $exif_data = process_TIFF_Header( $filehnd, "TIFF" );



        // Close File
        fclose($filehnd);
        return $exif_data;
}

memcache

$
0
0

Hi, I am new to this forum

I am exporering the possibility of using memcache. I use XAMPP on my Mac. I need to know if memcache is already installed, in phpinfo, there is a mod_mem_cache under apache2handler Loaded Modules.

If I think correctly, this is not the same as the php memcache.so, am I right?

 

If so, how do I find out if memcache.so is loaded? I tried the extension_loaded() function, it returns neither true or false. when I type php -m in the terminal, memcaches is not shown on the list.

how do I know for sure if memcache is loaded?

 

Thanks for your help in advance.

Warning: mysql_connect(): Unknown MySQL server host 'DB_HOST' (1)

$
0
0

Hello guys,

 

I am trying to run a script but it could not get connected to mysql and I have tried it on 2 different free hosts with different versions of php. I get this error:

 

Warning: mysql_connect(): Unknown MySQL server host 'DB_HOST' (1) in /home/u947202749/public_html/inc/functions.php on line 1918 Couldn't make connection.

 

Here is my function file with line 1917 to 1921

 function connect(){
        $link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");
        $db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");
        return $db;
    }

and here is my configuration file which is 100% accurately set according to right details but I wont share them here due to security reasons.

$site_url = "http://toorhamza12.fun2pk.com";
$site_name = "Image Hosting";
$site_title = "Image Hosting Script";
$site_meta_description = "Share your images";
$site_meta_keywords = "images, share";
$site_meta_author = "Zamfi";
$site_version = "1.2";
$logo_location = "css/img/logo.png";

// ADMIN CONFIGURATIONS
define("ADMIN_EMAIL", "admin@yoursite.com"); // email address for various notifications like IPN's confirmations or error logs, contact form and other administrative things.
define("UPLOAD_ONLY_REGISTERED", 0); // 1 = UPLOAD ONLY FOR REGISTERED USERS // 0 = UPLOAD FOR EVERYBODY

// DATABASE CONFIGURATIONS
define ("hidden", ""); // set database host
define ("hidden", ""); // set database user
define ("hidden",""); // set database password
define ("hidden",""); // set database name

and so on. Please help me regarding this issue. Thank You.

Best way to search through long strings

$
0
0

Hi,

 

Im working on a project where I have to sift through the entire HTML code of a webpage, and extract everything that lies within a certain HTML tag.  Essentially, at least as I see it, I need to sort through the entire webpage html source and find all occurrences of a certain html tag.

 

What would be the best way to do this?  I want to be sure to do it efficiently as I will be searching through ~2500 lines of html for each time the script is called.

 

Thanks in advance. 


$_POST reads an empty array

$
0
0

This has me stumped.  It was workign fine but 30 minutes ago!

 

Body of my form:

<form name="form1" id="form1" action="process.php" method="post">
<textarea cols="50" rows="4" id="src" name="src"></textarea>
<input type="submit" value="Submit">
</form>

process.php:

<?php print_r($_POST); ?>

process.php displays:

Array()

regardless of what I have in the text box.

Creating a search engine and linking blog posts

$
0
0

G'day,

 

I created my own simple blog with some posts in it, the posts are stored in a folder called "posts" and there in .MD format. I want to put a search engine on my blog when they search anything that looks similar to any blog.. it should show the results.. I can create a MySQL dB but I don't what do I add in the fields? And how do I link them?

 

If you still don't get me, let me know. I'll explain briefly.

 

Thank you.

Php -> function

$
0
0

Hello guys,

I am learning PHP and what better way to do it than reading and understanding code. 

But I have a question what does the function do?

-> 

Here is a sample code from MyBB


$username = &$this->data['username'];

And what does the & operator do? 

 

Thanks,

Abhi2011

php code

$
0
0

i am stuck wit uploading the image in the folder from the form and save the url to database. if any body could help me wit simple php code 

ftp_get() stopped working. Can't work out why

$
0
0

Hi guys

 

I'm not sure this is a PHP coding problem but it may be so I'm posting here anyway. I've got a script that runs as a cron job every few minutes that uses ftp_get() to pull a file from another server. I set this up in 2011 and it's been working flawlessly until a few days ago. I've just TeamViewered in to the remote computer where the files are being pulled from and had a look at the Filezilla FTP log. It's showing the successful FTP connection with the script but is then throwing a "425, Can't Open Data Connection" error.

 

I've just opened Dreamweaver and used exactly the same settings (remote address, user name, password etc.) and I was able to successful select and pull the file down via FTP. I checked the Filezilla log and transfer was successful with no 425 errors.

 

Here's the code in my script. It's very simple:

 
 
$c = ftp_connect('www.remotesite.com')     or die("Can't connect");
 
ftp_login($c,'username','password')     or die("Can't login");
 
ftp_get($c, $local_filelocation,$remote_filelocation, FTP_ASCII);
 
 
Viewing all 13200 articles
Browse latest View live