Jump to content

Or1g1naL

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Posts posted by Or1g1naL

  1. You thought? It's good that you read the page, but you should also read the part where it links you to the function(s) that are NOT deprecated.

    I already knew it was deprecated.  Everybody knows that.  jeez

     

    I'm just asking if uploading an image using a form is secure in your opinion.

    I don't want it to upload if it isn't an image file.

  2. ym_chaitu - I now understand what you're talking about.  Does this look better?

    if($type = "image"){
      $image_path = $image_directory.$_FILES['ufile']['name'][0];
      copy($_FILES['ufile']['tmp_name'][0], $image1_path);
    }
    

     

    It would be secure enough right?

  3. $ext = basename(strtolower($_FILES['ufile']['type'][0]; // "jpg"
    if($ext == "x-png" or $ext == "pjpeg" or $ext == "gif"){
      $image_path = $image_directory.$_FILES['ufile']['name'][0];
      copy($_FILES['ufile']['tmp_name'][0], $image1_path);
    }
    

     

    Is this a bad idea for public use?

  4. function updateNode($node, $nodeID, $childNode, $cnodeValue, $xmlFile){
       $dom = new DOMDocument();                
       $dom->load($xmlFile); 
       $node = $dom->getElementsByTagName($node);	 
     foreach($node as $nodes){
    	 if($nodes->getAttribute('id') == $nodeID){
    	   $nodes->getElementsByTagName($childNode)->item(0)->nodeValue = $cnodeValue;
      	 }
     }
     $dom->save($xmlFile);	 
    }
    
    
    
    if($_POST['update'] == 'Update'){
      
    updateNode("listing", $_POST['id'], "price", $_POST['price'], $xmlfile);
    updateNode("listing", $_POST['id'], "beds", $_POST['beds'], $xmlfile);
    updateNode("listing", $_POST['id'], "baths", $_POST['baths'], $xmlfile);
    updateNode("listing", $_POST['id'], "sqft", $_POST['sqft'], $xmlfile);
    updateNode("listing", $_POST['id'], "year", $_POST['year'], $xmlfile);
    updateNode("listing", $_POST['id'], "street", $_POST['street'], $xmlfile);
    updateNode("listing", $_POST['id'], "city", $_POST['city'], $xmlfile);
    updateNode("listing", $_POST['id'], "state", $_POST['state'], $xmlfile);
    updateNode("listing", $_POST['id'], "zip", $_POST['zip'], $xmlfile);
    
    }
    
    

     

    This is all my handy work and wonder what other more experienced people would do instead.

     

     

  5. function updateNode($node, $nodeID, $childNode, $cnodeValue, $xmlFile){
      
       $dom = new DOMDocument();                
       $dom->load($xmlFile); 
       $node = $dom->getElementsByTagName($node);
    
     foreach($node as $nodes){
       
    	 if($nodes->getAttribute('id') == $nodeID){
    	   $nodes->getElementsByTagName($childNode)->item(0)->nodeValue = $cnodeValue;
    
    	 }	   
    
    
     }
       $dom->save($xmlFile);
    
    }
    
    
    
    updateNode("contact", "4bafdebc54aac", "firstname", "Peter", "temp.xml");
    
    

     

    And it works!  :D

    Looks like it was my own confidence in my self that was holding me back.  I was sure I was creating the function wrong.

     

    Thanks guys

     

     

     

  6. and my first post!  I have lurked phpfreaks forum many times and copy little bits of code.  The information on this site is a lot of help and the people here are great.  Lately my code is looking messy because I dont' know how to create my own functions! :'( 

     

    Here is the code I want to turn into a function.  All this does is update a value in a xml file with the the attribute id  4bafdebc54aac.

     

    $contact_id = "4bafdebc54aac";
    $xmlfile = "temp.xml";
    
    $dom = new DOMDocument(); 
    $dom->load($xmlfile);
    $contacts = $dom->getElementsByTagName("contact"); 
    
    foreach($contacts as $contact){ 
    
       if($contact->getAttribute('id') == $contact_id){
         $contact->getElementsByTagName('firstname')->item(0)->nodeValue = "Jim";
    
     }
      
    } 
    $dom->save($xmlfile);
    
    

     

     

     

    This is my attempt to create a function from that, but it isn't working.  The code above this works perfectly but I can't put it into a function.

     

     

     

     

    function updateNode($node, $nodeID, $childNode, $cnodeValue, $xmlFile){
      
       $doc = new DOMDocument();                
       $doc->load($xmlFile); 
       $node = $dom->getElementsByTagName($node);
    
     foreach($node as $nodes){
       
    	 if($nodes->getAttribute('id') == $nodeID){
    	   $nodes->getElementsByTagName($childNode)->item(0)->nodeValue = $cnodeValue;
    
    	 }	   
    
    
     }
    
    
    }
    
    updateNode("contact", "4bafdebc54aac", "firstname", "Peter", "temp.xml");
    

     

    Everything looks ok to me but it does not work.  Could anybody give me any tips?  I would really be greatful.

×
×
  • 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.