PHP - Moved: Unable To Transfer Variables Between Two Files !
This topic has been moved to Third Party PHP Scripts.
http://www.phpfreaks.com/forums/index.php?topic=343041.0 Similar TutorialsThis topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=350034.0 I'm not asking for specific coding help, but what I am looking for is an answer from someone who might have dealt with this in the past and can help shed some light on the subject. I'm working on a website that allows the user to upload several images at a time. I have serverA that hosts the website and database and serverB that hosts the image uploads. I'm looking for the best (preferably the fastest) method to transfer image files from serverA to serverB. I know I can transfer the files through FTP in PHP and I can also do it via HTTP by making a small script on serverB that would accept _POST transfers of each file.. Are there other methods? Remember, there are 2-3 images sent each time.. so just because a method might be "preferred," I don't want to make the user wait longer than they have to. Thanks for your time. I got this script: But it give me error, file_get_contents cannot open stream. I need to add the FTP connection with user/pass paramaters. then look in set http url, to get the file contents(images) and transfer to ftp server location. Can Anyone take alook and tell me if I am going down the right path and how to get there. Please Code: [Select] function postToHost($host, $port, $path, $postdata = array(), $filedata = array()) { $data = ""; $boundary = "---------------------".substr(md5(rand(0,32000)),0,10); $fp = fsockopen($host, $port); fputs($fp, "POST $path HTTP/1.0\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: multipart/form-data; boundary=".$boundary."\n"); // Ab dieser Stelle sammeln wir erstmal alle Daten in einem String // Sammeln der POST Daten foreach($postdata as $key => $val){ $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; } // Sammeln der FILE Daten if($filedata) { $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$filedata['name']."\"; filename=\"".$filedata['name']."\"\n"; $data .= "Content-Type: ".$filedata['type']."\n"; $data .= "Content-Transfer-Encoding: binary\n\n"; $data .= $filedata['data']."\n"; $data .= "--$boundary--\n"; } // Senden aller Informationen fputs($fp, "Content-length: ".strlen($data)."\n\n"); fputs($fp, $data); // Auslesen der Antwort while(!feof($fp)) { $res .= fread($fp, 1); } fclose($fp); return $res; } $postdata = array('var1'=>'today', 'var2'=>'yesterday'); $filedata = array( 'type' => 'image/png', 'data' => file_get_contents('http://xxx/tdr-images/images/mapping/dynamic/deals/spot_map') ); echo '<pre>'.postToHost ("localhost", 80, "/test3.php", $postdata, $filedata).'</pre>'; Hi Guys, I am relatively new to php, and have hit a problem. Basically I am writing a PHP socket server - which acts as a socket server for a swish movie. The only way of getting data into the swish movie is one function - loadvariablesnum() - which uses 'post' or 'get'. The swish movie is a web GUI for a system and therefore needs a reasonably decent refresh rate - 5 times a second for example. Originally I wrote a php file that created / bound / listened to the socket and then entered an infinite while loop that would read from the socket and echo the output to the swish movie. The problem with this method, was that each time the swish movie called loadvariablesnum() the PHP script would re-open - re-bind - re-listen to the socket - which caused all sorts of problems for my client. Therefore I decided to re-write the PHP file that included functions: Code: [Select] <? //TCP_Socket_Server.php global $output; function TCP_Socket_Server() { $host = "10.10.13.59"; $port = 10000; set_time_limit(0); $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n"); $result = socket_bind($socket, $host, $port);// or die("Could not bind to socket\n"); $result = socket_listen($socket, 3) or die("Could not set up socket listener\n"); socket_set_block($socket); $spawn = socket_accept($socket) or die("Could not accept incoming connection\n"); // read client input while(1) { $input = socket_read($spawn, 10000);// or die("Could not read input\n"); $input = trim($input); global $output; $output = $input; WriteData(); flush(); } socket_close($spawn); socket_close($socket); } function WriteData() { static $LocalTemp; global $output; $LocalTemp = $output; $TempBuffer = "&TCP_SocketServerBufferVar="; //$TempBuffer .= $GLOBALS['output']; $TempBuffer .= $LocalTemp; echo $TempBuffer; } ?> Using this method I can call TCP_Socket_Server() only once at the beginning of the swish movie using the loadvariablesnum() (from another PHP file), which sets the server running - e.g. Code: [Select] <? //Load_Server.php include 'TCP_Socket_Server.php'; TCP_Socket_Server(); ?> My plan was to then call the WriteData() function regularly approximately 5x per second, (again from another PHP file using loadvariablesnum() in swish): Code: [Select] <? //Write_Data.php include 'TCP_Socket_Server.php'; Write_Data(); ?> However, when I call this function from an external PHP file - no valid data is output by echo - even though I can see the data being received (in the browser) in the main Load_Server.php page - which is output using the same Write_Data() function. I have tried many different ways of accessing this variable ($output) from a different php file - e.g returning the variable from Write_Data() - which had the same result (i.e. no valid data). I have also tried using sessions, but could only seem to get them to work in files that did not run indefinitely - e.g. without the infinite while loop in TCP_Socket_Server(). I am currently running the PHP files (and the rest of the web content) on APACHE2 - in Ubuntu. I would really appreciate any advice on this - as at the moment, this looks like a show stopper - and would waste 2 months work. Hy! I have 3 files: file 1 (index.php) includes 2 files: file2.php and file3.php File2.php contains $aditionalStuff and in file3.php I want to use $aditionalStuff, but it wont work (like it wasn't initialized). How can I make this work? index.php include "file2.php"; include "file3.php"; file2.php $aditionalStuff = 'some stuff'; file3.php echo $aditionalStuff; Thanks! Hi, i'm new to php and am trying to call $variables in different in multiple hierarchy from one main variable file. I have one main file called variables.php that contain a list of variables <?php $variable1 = 'root/main/'; $variable2 = 'welcome'; $variable3 = 'testing'; ?> a second file called file1.php in the same directory as the variables.php file <?php require 'varibles.php'; include $variable1 . 'testing.php' ?> a third file called testing.php inside root/main/ <?php echo $variable2; include $varible1 . 'temp/abc.php'; ?> a fourth file called abc.php inside root/main/temp <?php echo $variable3; ?> the problem is testing.php is able to echo $variable2 but abc.php is not able to echo $variable3...is there a limit to the level of files before it can't echo a variable? Hi, I'm having a bit of a problem sharing some variables I have across a few files. My first file (index.php) calls an ajax request for (display.php) and sends a few variables to it. All fine so far. display.php then does its thing and displays the content on index.php as it should. Now in display.php I need a variable to be passed back to index.php for use in a menu. I've tried setting a session variable in display.php but unfortunately this doesn't seem to work. I also can't use get or post as I don't want to refresh the page. Really scratching my head over this one! Edd This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=321950.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=319414.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=345120.0 I am making a framework for my site, and I have a folder which defines some things. One thing it defines is the location of the frame work: define('FRAMEWORK', '../../../framework'); Next I include a specific class that I include: include FRAMEWORK.'/commons/Music.php'; This class extends the main framework include '../Weblyize.php'; class Music extends Weblyize{ // Some code } This issue I am currently having is Warning: include(../Weblyize.php) the file Weblyize.php is a directory above Music.php So, here is where the webpage is located: http://96.42.108.211:3333/templates/music/music1/about.php Here is where the two classes are located (sub classes are in commons) http://96.42.108.211:3333/framework/Weblyize.php http://96.42.108.211:3333/framework/commons/Music.php What is a good way to link the files together with out this breaking no matter where the framework directory is located? This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=353684.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=358363.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=328735.0 This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=330778.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=321151.0 This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=333379.0 This topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=357370.0 This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=314375.0 |