PHP - Copying Content
Hi all,
Maybe someone can help me with this, I am looking to copy specific content from one website to another automatically. So when ever one website updates the certain content the other site is automatically updated with it to. I have tried using file_get_contents but this wasnt working. Does anyone have any ideas? Im looking to copy https://annablais.scentsy.us/Home starting at line 270, the end is determined by how many Parties there are. Thanks all Similar TutorialsI want to copy everything in templates/blue to the folder code/ However: shell_exec("cp -r 'templates/blue' 'code'"); Creates a folder called blue inside code. I tried cp -r 'templates/blue/*' 'code', but that didn't do anything. Any ideas? Ok fellas....this one has me stumped. I am trying to copy a whole bunch of pictures from one directory into a new directory. However, the new directory will store the images based upon the user's id. Initially I stored all the images in one directory. HUGE mistake.. That single directory is over 5GB and takes and eternity to open and edit the files for 1 single user. So I need to separate them out. Anyways, here is what I am trying to do in theory. All the information about the user and the file they uploaded is stored in my database. But how do I create a script that is somewhat dynamic? One that will refresh the copy file script for each result. Here is the general idea....or a conversation starter code i am working with so far. Code: [Select] <?php include 'db_connect.php'; $userId=2; // Make the directory that will store the users images with the desired folder structure $structure = './images/' .$userId. ''; // create the directory and set permissions if (!mkdir($structure, 0777, true)) { die('Failed to create folder'); chmod($structure, 0777); } //Query the database for the images $query_image = "SELECT * FROM images WHERE angler=$userId ORDER BY submit_id DESC"; $image_result = mysql_query($query_image) or die(mysql_error()); // get count of how many rows in case we need that info $rowCount = mysql_num_rows($image_result); //get the results into an array by setting each result as a variable while($row = mysql_fetch_assoc($image_result)) $galleryresults[]= $row; //now move files $file = './submitted_pics/{$galleryresults[0]['image']}'; $newfile = './images/' .$userId. '/{$galleryresults[0]['image']}'; if (!copy($file, $newfile)) { echo "failed to copy $file...\n"; } ?> Ok, I would just like some advice on how to go about doing something. A website that alot of my friends use to make their builds in-game goes down frequently causing them not to be able to pull up their build information. I would like to be able to use php to copy not only the html source, but the images as well to my websvr to be able to view when their site is offline. Now I know I could simply just click page -> save as complete html in internet explorer and then upload that... However I don't want to have to do that for everyone stuff.. its time consuming.. I was hoping to automate the process with a script. I know how to get the html source from a website, but I don't know how to pull the content "pictures ect." to make it actually look like their site and have more than just text. I'll appreciate any advice you can give, I think some simple direction should be enough to get me going. I'm trying to allow a user to upload an image, and have that image copied to an Image folder on the server When I run the code I get the success message near the bottom of the code, but the image never gets copied to the folder. I'm not sure what's causing it to not copy the image if($_POST["store"] != "") // if upload was hit { $fileExt = strrchr($_FILES['userfile']['name'], "."); // grab extension if($fileExt != ".jpg" && $fileExt != ".jpeg") // check extension { $_SESSION["badFileType"] = "You cannot upload a file of type ".$fileExt; // set error } else { $fileName = $_FILES['userfile']['name']; // set file name if(!is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "Problem: possible file upload attack!"; // set error exit(); // end } $upfile = "../Images/lg_".$category.$counter.".jpg"; // set path $newFileName = $category.$counter.".jpg"; // set new file name if(!copy($_FILES['userfile']['tmp_name'], $upfile)) // if not able to copy { echo "Problem: file could not be copied to directory!"; // set error exit(); // end } $_SESSION["badfileType"] = "File uploaded successfully!"; // set success message } } else { $_SESSION["badFileType"] = ""; // clear error } This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=313840.0 I'm using copy() to copy an image to a different directory. The problem is the image could be in 1 of 3 folders. With out knowing which folder its in how can I do this? I'm trying to compare 2 files, each with data separated by ::. I'm trying to make a comparison that if the data to the left of the separator from one file is not found in the same column of the other file, then it is copied to an array. For example: file1.txt abc::def ggg::hhh mmm::ppp file2.txt abc::def zzz::aaa bbb::ccc So... ggg::hhh mmm::ppp is copied from file1.txt because ggg and mmm was not found on the same side in file2.txt ...but I'm not getting any error message with this. The operation just hangs. Code: [Select] <?php $dic1 = file('file1.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $dic2 = file('file2.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $titleText = array(); // Storing results into this array. foreach ($dic1 as $dic1line){ list($dic1field1, $dic1field2) = explode('::', $dic1line); foreach ($dic2 as $dic2line){ list($dic2field1, $dic2field2) = explode('::', $dic2line); if ($dic1field1 != $dic2field1) { // Found a non match in DB. array_push($titleText, "$dic1field1 :: $dic1field2\n"); // Store all finds in array. } } } // Finish outputting anything left over. if (empty($titleText)) { // $value was not found -- array is empty. echo 'All matched, or something else.'; } else { $arrayOut = implode("", $titleText); // output the results found in the search. echo $arrayOut; } unset($value); ?> Anyone know how to do this? Thanks. I've been developing a php application that runs my entire company for the last 4 years. One of the things I never thought of until now is that the server guys or anyone else could copy the source code and db and be able to start up another company which brings up my question to you.... How would you protect your application? My thought is to create one small php file that is encrypted with something that is required to make the entire site run (not sure at this point what it would be that they couldn't just rebuild). Then if this file sees it's on a different domain/ip it requests data from my site which logs the info for me to look at. If I find out it's something not approved, it would then not allow the program to run and will give a error. What is your idea? Hi, I will start off trying to explain what I am trying to make the best I can. What I want to create is a script that gets the gold value from this website: http://www.lbma.org.uk/pages/index.cfm?page_id=46&title=current_statistics and then save it to a variable which I will use to calculate values of different gold karats. Here is the content in bold I need on the website I linked: Quote LONDON GOLD FIXING USD GBP EUR AM 1588.00 1005.127 1251.083 PM 1589.50 1004.741 1249.803 So what help do I need? Well, I don't expect you to figure out the calculating part for me but some help how to get that content pointed out above and save it to a variable is what I would appreciate getting some help with. I don't know much PHP, only some and I have been trying to figure this out for a day now without any success. I suppose php get contents and/or curl should be used here but I don't know how really. I would very much appreciate the help I can get on this. Thank you! What I'm trying to do is copy all files from one server to another folder on another server. Here is what I have have so far.. <?PHP //connection settings $ftp_server = "server"; $ftp_user_name = "user"; $ftp_user_pass = "pass"; $dir = "/var/test/"; $destination_file = "/test/"; // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server, for user $ftp_user_name"; } if (ftp_chdir($conn_id, $dir)) { echo " <br/>Current directory is now: " . ftp_pwd($conn_id) . "\n<p/>"; } else { echo "Couldn't change directory\n<p/>"; } $buff = ftp_rawlist($conn_id, $dir); foreach($buff as $files) { echo $files. "<br/>"; if (ftp_get($conn_id, $destination_file."test.file", $dir."test.txt", FTP_BINARY)) { echo "<br/>Successfully written to $destination_file\n"; } else { echo "There was a problem\n"; } ?> That doesn't work. Any ideas? Thanks, Sean This is the Code i am using. This is show error: Fatal error: Call to a member function item() on a non-object in /home/domain/public_html/forum/file/Test.php on line 35 Code: [Select] <?php $xml=("http://www.vn-zoom.com/external.php?type=RSS2&forumids=77"); $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); //get elements from "<channel>" $channel=$xmlDoc->getElementsByTagName('channel')->item(0); $channel_title = $channel->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $channel_link = $channel->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $channel_desc = $channel->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; //output elements from "<channel>" echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>"); echo("<br />"); echo($channel_desc . "</p>"); //get and output "<item>" elements $x=$xmlDoc->getElementsByTagName('item'); $i=1; // $i = 1 to n (I use For here). { $item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; // If i remove this, it will work....//////////// $item_content=$x->item($i)->getElementsByTagName('content') ->item(0)->childNodes->item(0)->nodeValue; ///////////////////////////////////////////////////// echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br />"); echo ($item_desc . "</p>"); echo ("<br />"); echo ($item_content . "</p>"); } ?> Please help me Fix this Code to Get content of Tag Name <content:encoded> Thanks Hi guys im in the middle of optimizing code.. Code: [Select] $sql = "SELECT * FROM sa_enemystats WHERE username='$username'"; $res = mysql_query($sql); while ($row = mysql_fetch_assoc($res)) { $enemy['current_health'] = $row['current_health']; $enemy['current_skill'] = $row['current_skill']; $enemy['level'] = $row['level']; $enemy['damage'] = $row['damage']; $enemy['evade'] = $row['evade']; $enemy['accuracy'] = $row['accuracy']; $enemy['speed'] = $row['speed']; $enemy['luck'] = $row['luck']; echo 'debug: variables synced with db table'; }I know that the setting of these variables are messy and can be done in a better way... but how? I have tried foreach and copying other's code for an array copy but it lead no where. Then again my syntax could be wrong... I used something like Code: [Select] foreach ( $enemy[$value] as $row => $value) { $enemy[$value] = $row[$value]; } How can i get the content of the array? Or is the array empty? Code: [Select] <?php include "../../../config.php"; include "../../../lib.php"; $words = $_POST['wordids']; print_r2($words); for($i = 0; $i < count($words); $i++) { echo "test"; $word = $words[i]; print_r2($word); } ?> Quote Array ( => Array [1] => Array [2] => Array [3] => Array [4] => Array ) test test test test test In case it helps, this is the form that sends the info: Code: [Select] <?php include 'config.php'; include 'lib.php'; $db = dbConnect(); $words = getWords(); dbClose($db); ?> <html> <head> <title>Historer : Words</title> </head> <body> <? if(isset($_GET['removed'])) { ?><div id="message">Removed <? echo $_GET['removed'] ?></div> <? } ?> <div id="container"> <form method="post" action="inc/php/utils/word-exclude.php"> <input type='submit' name='submit' value='Exclude Selected Words'> <table> <tr> <td>word</td> </tr> <? foreach($words as $word) { ?> <tr> <td><input type="checkbox" name="wordids[]" value="<?=$word?>"><?=$word[word]?></td> </tr> <? } ?> </table> </form> </div> </body> </html> Hi, I am building function to convert the db table to an XML file. But I want to retrieve the root node value from the FIRST row in that db table before I build a for loop to traverse that db table. Let's say I have this table NodeInfo: node_Id source target ====== ===== ===== 1 email to 2 to toFirstName pseudocode for what I want: 1) store root (the source field of table NodeInfo 2)for each entry in table NodeInfo, do: build XML END FOR-EACH Any help much appreciated! Hello I want get content of website and insert it to my website This website have 2000 page and each one have 10 post. I developed some code but I've some problem: Code: [Select] for($i=1;$i<=3;$i++) //$i is website pages { //download main page $maincatst = file_get_contents($catlink.$i); //$catlink select link of category of website //number of post in main page for ($j=1;$j<=10;$j++) { $linkposttmp = TextBetween('before link','after link',$maincatst) ; $link = TextBetween('before link','after link>',$linkposttmp); // download content of each link $main_post_str = file_get_contents($link); My problem is when run this file only download first link of each mainpage. anyone can help me? Hi i was using the code below to redirect user when a link like. www.site.com/?redirect was clicked, instead how do i add things to the page like "html code goes here" instead of the header? <?php $link ='http://www.whereitredirectstoo.co.uk'; if (isset($_GET['redirect'])) header('Location: ' . $link); ?> thanks I want to display 50 results, theirfore I'm using a while loop to do so, the issue is, if $row consists of results lower then 50 (it will display them) and not display 50..so I'm trying to figure out a way so even if $row doesn't cosist of 50 i'll display what it has aswell as continue the $i (and for the rest display NO CONTENT). I've come up with the following on the spot (not sure if it even would work) - but was wanting a better solution. $i = 0; $results = mysql_num_rows($result); while ($row = mysql_fetch_assoc($result)) { $i++; echo $i .' CONTENT '.$row['name'].'<br />'; } if ($result < 50) { for($i <= 50 - $result; $i++) { echo $i .' NO CONTENT<br />'; } } Hi all, I would need some advice on the best way to implement an exclusive section in a website. We will be generating say 10,000 unique numbers and sending a unique one to each of our customers. Said customer will enter that number on the site and will be granted access to an exclusive section. How would I validate each number? Do I import those 10,000 numbers in mysql and check if an entered number exists? Or can I simply use a textfile as a database with all those numbers? Are there any solutions for this already made? Thanks in advance! |