Search Results

Search found 222 results on 9 pages for 'fwrite'.

Page 5/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • Unable to open a file for writing

    - by asdasdas
    I am trying to write to a file. I do a file_exists check on it before I do fopen and it returns true (the file does exist). However, the file fails this code and gives me the error every time: $handle = fopen($filename, 'w'); if($handle) { flock($handle, LOCK_EX); fwrite($handle, $contents); } else { echo 'ERROR: Unable to open the file for writing.',PHP_EOL; exit(); } flock($handle, LOCK_UN); fclose($handle); Is there a way I can get more specific error details as to why this file does not let me open it for writing? I know that the filename is legit, but for some reason it just wont let me write to it. I do have write permissions, I was able to write and write over another file.

    Read the article

  • Write pointer to file in C

    - by Sergey
    I have a stucture: typedef structure student { char *name; char *surname; int age; } Student; I need to write it to binary file. Student *s = malloc(sizeof(*s)); I fill my structure with data and then i write in to the file: fwrite(s, sizeof(*s), 1, fp); In my file doesnt exist a name and surname, it have an adresses of char*. How can i write to file a word, not an adresses?

    Read the article

  • How to get Joomla users data into a json array

    - by sami
    $sql = "SELECT * FROM `jos_users` LIMIT 0, 30 "; $response = array(); $posts = array(); $result=mysql_query($sql); while($row=mysql_fetch_array($result)) { $id=$row['id']; $id=$row['name']; $posts[] = array('id'=> $title, 'name'=> $name); } $response['jos_users'] = $posts; $fp = fopen('results.json', 'w'); fwrite($fp, json_encode($response)); fclose($fp); I want to fetch the user id and name to the json file.i thought id did wrong code.can anyone correct it ?

    Read the article

  • Paypal development. encrypt transactions. php p12

    - by ninchen
    when i take a look at the paypal documentation, they say "Note that the PayPal SDK for PHP does not require SSL encryption". https://developer.paypal.com/docs/classic/api/apiCredentials/#encrypting-your-certificate Is the statement of this phrase, that i don't have to create a p12 certificate when working with php, but use the public_key.pem and paypal_public_key.pem? If yes: Is it secure enough to create the encrypted form input elements without p12 certificate? If no: What do they mean? :-) Before this question came up, i've tested this little programm. http://www.softarea51.com/blog/how-to-integrate-your-custom-shopping-cart-with-paypal-website-payments-standard-using-php/ There is a config file paypal-wps-config.inc.php where i can define the paths to my certificates. // tryed to use // 'paypal_cert.p12 '; $config['private_key_path'] = '/home/folder/.cert/pp/prvkey.pem'; // must match the one you set when you created the private key $config['private_key_password'] = ''; //'my_password'; When i try to use the p12 certificate, openssl_error_string() returns "Could not sign data: error:0906D06C:PEM routines:PEM_read_bio:no start line openssl_pkcs7_sign When i instead use the prvkey.pem without password all works fine. Here is the function, which signs and encrypt the data. function signAndEncrypt($dataStr_, $ewpCertPath_, $ewpPrivateKeyPath_, $ewpPrivateKeyPwd_, $paypalCertPath_) { $dataStrFile = realpath(tempnam('/tmp', 'pp_')); $fd = fopen($dataStrFile, 'w'); if(!$fd) { $error = "Could not open temporary file $dataStrFile."; return array("status" => false, "error_msg" => $error, "error_no" => 0); } fwrite($fd, $dataStr_); fclose($fd); $signedDataFile = realpath(tempnam('/tmp', 'pp_')); **// here the error came from** if(!@openssl_pkcs7_sign( $dataStrFile, $signedDataFile, "file://$ewpCertPath_", array("file://$ewpPrivateKeyPath_", $ewpPrivateKeyPwd_), array(), PKCS7_BINARY)) { unlink($dataStrFile); unlink($signedDataFile); $error = "Could not sign data: ".openssl_error_string(); return array("status" => false, "error_msg" => $error, "error_no" => 0); } unlink($dataStrFile); $signedData = file_get_contents($signedDataFile); $signedDataArray = explode("\n\n", $signedData); $signedData = $signedDataArray[1]; $signedData = base64_decode($signedData); unlink($signedDataFile); $decodedSignedDataFile = realpath(tempnam('/tmp', 'pp_')); $fd = fopen($decodedSignedDataFile, 'w'); if(!$fd) { $error = "Could not open temporary file $decodedSignedDataFile."; return array("status" => false, "error_msg" => $error, "error_no" => 0); } fwrite($fd, $signedData); fclose($fd); $encryptedDataFile = realpath(tempnam('/tmp', 'pp_')); if(!@openssl_pkcs7_encrypt( $decodedSignedDataFile, $encryptedDataFile, file_get_contents($paypalCertPath_), array(), PKCS7_BINARY)) { unlink($decodedSignedDataFile); unlink($encryptedDataFile); $error = "Could not encrypt data: ".openssl_error_string(); return array("status" => false, "error_msg" => $error, "error_no" => 0); } unlink($decodedSignedDataFile); $encryptedData = file_get_contents($encryptedDataFile); if(!$encryptedData) { $error = "Encryption and signature of data failed."; return array("status" => false, "error_msg" => $error, "error_no" => 0); } unlink($encryptedDataFile); $encryptedDataArray = explode("\n\n", $encryptedData); $encryptedData = trim(str_replace("\n", '', $encryptedDataArray[1])); return array("status" => true, "encryptedData" => $encryptedData); } // signAndEncrypt } // PPCrypto The main questions: 1. Is it possible to use p12 cert with php, or is it secure enough to work without it? 2. Why i become an error when using openssl_pkcs7_sign Please help. Greetings ninchen

    Read the article

  • I'd like to know why a function executes fine when called from x but not when called from y

    - by Roland
    When called from archive(), readcont(char *filename) executes fine! Called from runoptions() though, it fails to list the files "archived"! why is this? The program must run in terminal. Use -h as a parameter to view the usage. This program is written to "archive" text files into ".rldzip" files. readcont( char *x) should show the files archived in file (*x) a) Successful call Use the program to archive 3 text files: rldzip.exe a.txt b.txt c.txt FILEXY -a archive() will call readcont and it will work showing the files archived after the binary FILEXY will be created. b) Unsuccessful call After the file is created, use: rldzip.exe FILEXY.rldzip -v You can see that the function crashes! I'd like to know why is this happening! /* Sa se scrie un program care: a) arhiveaza fisiere b) dezarhiveaza fisierele athivate */ #include<stdio.h> #include<stdlib.h> #include<conio.h> #include<string.h> struct content{ char *text; char *flname; }*arc; FILE *f; void readcont(char *x){ FILE *p; if((p = fopen(x, "rb")) == NULL){ perror("Critical error: "); exit(EXIT_FAILURE); } content aux; int i; fread(&i, sizeof(int), 1, p); printf("\nFiles in %s \n\n", x); while(i-- >1 && fread(&aux, sizeof(struct content), 1, p) != 0) printf("%s \n", aux.flname); fclose(p); printf("\n\n"); } void archive(int argc, char **argv){ int i; char inttext[5000], textline[1000]; //Allocate dynamic memory for the content to be archived! arc = (content*)malloc(argc * sizeof(content)); for(i=1; i< argc; i++) { if((f = fopen(argv[i], "r")) == NULL){ printf("%s: ", argv[i]); perror(""); exit(EXIT_FAILURE); } while(!feof(f)){ fgets(textline, 5000, f); strcat(inttext, textline); } arc[i-1].text = (char*)malloc(strlen(inttext) + 1); strcpy(arc[i-1].text, inttext); arc[i-1].flname = (char*)malloc(strlen(argv[i]) + 1); strcpy(arc[i-1].flname, argv[i]); fclose(f); } char *filen; filen=(char*)malloc(strlen(argv[argc])+1+7); strcpy(filen, argv[argc]); strcat(filen, ".rldzip"); f = fopen(filen, "wb"); fwrite(&argc, sizeof(int), 1, f); fwrite(arc, sizeof(content), argc, f); fclose(f); printf("Success! "); for(i=1; i< argc; i++) { (i==argc-1)? printf("and %s ", argv[i]) : printf("%s ", argv[i]); } printf("compressed into %s", filen); readcont(filen); free(filen); } void help(char *v){ printf("\n\n----------------------RLDZIP----------------------\n\nUsage: \n\n Archive n files: \n\n%s $file[1] $file[2] ... $file[n] $output -a\n\nExample:\n%s a.txt b.txt c.txt output -a\n\n\n\nView files:\n\n %s $file.rldzip -v\n\nExample:\n %s fileE.rldzip -v\n\n", v, v, v, v); } void runoptions(int c, char **v){ int i; if(c < 2){ printf("Arguments missing! Use -h for help"); } else{ for(i=0; i<c; i++) if(strcmp(v[i], "-h") == 0){ help(v[0]); exit(2); } for(i=0; i<c; i++) if(strcmp(v[i], "-v") == 0){ if(c != 3){ printf("Arguments misused! Use -h for help"); exit(2); } else { printf("-%s-", v[1]); readcont(v[1]); } } } if(strcmp(v[c-1], "-a") == 0) archive(c-2, v); } main(int argc, char **argv) { runoptions(argc, argv); }

    Read the article

  • [PHP] - Lowering script memory usage in a "big" file creation

    - by Riccardo
    Hi there people, it looks like I'm facing a typical memory outage problem when using a PHP script. The script, originally developed by another person, serves as an XML sitemap creator, and on large websites uses quite a lot of memory. I thought that the problem was related due to an algorithm holding data in memory until the job was done, but digging into the code I have discovered that the script works in this way: open file in output (will contain XML sitemap entries) in the loop: ---- for each entry to be added in sitemap, do fwrite close file end Although there are no huge arrays or variables being kept in memory, this technique uses a lot of memory. I thought that maybe PHP was buffering under the hood the fwrites and "flushing" data at the end of the script, so I have modified the code to close and open the file every Nth record, but the memory usage is still the same.... I'm debugging the script on my computer and watching memory usage: while script execution runs, memory allocation grows. Is there a particular technique to instruct PHP to free unsed memory, to force flushing buffers if any? Thanks

    Read the article

  • C++ program runs slow in VS2008

    - by Nima
    I have a program written in C++, that opens a binary file(test.bin), reads it object by object, and puts each object into a new file (it opens the new file, writes into it(append), and closes it). I use fopen/fclose, fread and fwrite. test.bin contains 20,000 objects. This program runs under linux with g++ in 1 sec but in VS2008 in debug/release mode in 1min! There are reasons why I don't do them in batches or don't keep them in memory or any other kind of optimizations. I just wonder why it is that much slow under windows. Thanks,

    Read the article

  • receive xml file via post in php

    - by thegunner
    Hi, I'm looking for a PHP script that can accept an XML file via a POST, then send a response.... Does anyone have any code that could do this? So far the only code I have is this but not sure about the response or if indeed I am even going in the right direction as XML characters are not saved correctly. Any ideas? <?php if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){ $postText = file_get_contents('php://input'); } $datetime=date('ymdHis'); $xmlfile = "myfile" . $datetime . ".xml"; $FileHandle = fopen($xmlfile, 'w') or die("can't open file"); fwrite($FileHandle, $postText); fclose($FileHandle); ?> Thanks,

    Read the article

  • crontab won't work on mac 10.6.7

    - by ohana
    i create a simple cron job by editing /etc/crontab as following: */2 * * * * * php /Users/min/Documents/testcron.php and the testcron.php is simple as: <?php $fd = fopen("/Users/min/Documents/testcron.txt", 'a'); fwrite($fd, "test--cron--\n"); fclose($fd); ?> then simply save the crontab file and hope magic happen, but nothing happened. i even run the command manually and it worked. php /Users/min/Documents/testcron.php anyone have any idea? Thanks

    Read the article

  • linux's fork and system resources

    - by Dmitry Bespalov
    Suppose I have following code in linux: int main() { FILE* f = fopen("file.txt", "w"); fork(); fwrite("A", 1, 1, f); fclose(f); return 0; } What I know about fork from documentation, is that it makes the copy of current process. It copies state of the memory as well, so *f should be equal in both instances. But what happens with system resources, such as a file handle? In this example I open the file with write intentions, so only one instance can write into file, right? Which of the instances will actually write into file? Who should care further about the file handle, and call fclose() ?

    Read the article

  • PHP Readfile() number of bytes when user aborted

    - by jtnire
    Hi Everyone, I'm using a PHP script to stream a live video (i.e. a file which never ends) from a remote source. The output is viewed in VLC, not a web browser. I need to keep a count of the number of bytes transferred. Here is my code: <?php ignore_user_abort(true); $stream = $_GET['stream']; if($stream == "vid1") { $count = readfile('http://127.0.0.1:8080/'); logThis($count); } function logThis($c) { $myFile = "bytecount.txt"; $handle = fopen($myFile,'a'); fwrite($handle,"Count: " . $c . "\n"); fclose($handle); } ?> However it appears that when the user presses the stop button, logThis() is never called, even though I've put in ignore_user_abort(true); Any ideas on what I'm doing wrong? Thanks

    Read the article

  • Turing's Craft exercise stumped me... seems too easy.

    - by Chris
    "Write a for loop that prints the integers 1 through 40, separated by spaces or new lines. You may use only one variable, count which has already been declared as an integer." So I use... for(count = 1; count <= 40; count++) { cout << " " << count; } but they are using stdio.h as the only header and cout is not recognized. It hints that the output format should be (" ",count), but I can't figure out what print function to use. stdio.h can use fprintf or fwrite, but I don't have enough parameters for either function. Any ideas?

    Read the article

  • PHP socket UDP communication

    - by Ghedeon
    Server works fine, but the problem is the client doesn't receive anything. server.php <?php $buf_size = 1024; $socket = stream_socket_server("udp://127.0.0.1:3127", $errno, $errstr, STREAM_SERVER_BIND); do { $str = stream_socket_recvfrom($socket, $buf_size, 0, $peer); $str = "abc"; stream_socket_sendto($socket, $str, strlen($str), 0, $peer); } while (true); ?> client.php <?php $fp = stream_socket_client("udp://127.0.0.1:3127", $errno, $errstr); if (!$fp) { echo "$errno - $errstr<br />\n"; } else { fwrite($fp, "1 2 3"); echo fread($fp, 15); fclose($fp); } ?>

    Read the article

  • using php Download File From a given URL by passing username and password for http authentication

    - by Acharya
    Hi all, I need to download a text file using php code. The file is having http authentication. What procedure I should use for this. Should I use fsocketopen or curl or Is there any other way to do this? I am using fsocketopen but it does not seem to work. $fp=fsockopen("www.example.com",80,$errno,$errorstr); $out = "GET abcdata/feed.txt HTTP/1.1\r\n"; $out .= "User: xyz \r\n"; $out .= "Password: xyz \r\n\r\n"; fwrite($fp, $out); while(!feof($fp)) { echo fgets($fp,1024); } fclose($fp); Here fgets is returning false. Any help!!!

    Read the article

  • Determining Terminal lines/cols via PHP CLI

    - by eFrane
    I know that it is quite easy to figure out a terminal's size parameters via the stty -a command. When using local CLI PHP scripts, there is no problem at all on grabbing that output via system() or so. But I am trying the same thing via a php script started from an ssh command. Sadly, all that stty ever returns is: stty: standard input: Invalid argument. The calling code is: exec('stty -a | head -n 1', $query); echo $query[0]; So the question is: If I can output to the terminal and read input from it (e.g. can fread() from STDIN and fwrite() to STDOUT in PHP, shouldn't stty also have valid STDIN and STDOUT?

    Read the article

  • PHP export to text file - Only saving first line.

    - by wertz8090
    I'm trying to export some extracted $_POST information into a text file, however my code is only capturing the first variable and ignoring the rest. I'm saving the information to the text file in this manner: $values = "First Name: $fName\r\n"; $values .= "Last Name: $lName\r\n"; $values .= "Address: $address\r\n"; etc. This is the code I use to write to the text file: $fp = @fopen("person.data", "w") or die("Couldn't open person.data for writing!"); $numBytes = @fwrite($fp, $values) or die("Couldn't write values to file!"); @fclose($fp); Any ideas on why it would only save the first $values ($fName) variable but not the rest of them? It actually saves the first part of the $values string for all of them (so I see Last Name:, Address:, etc. on separate lines in the text file) but the called variables $lName and $address do not appear.

    Read the article

  • scoket connection issue+php

    - by Abhimanyu
    Hi, I am using PHP socket programming and able to write data to open socket but i have to wait for a long time(or stuck it)for the response or some time getting error like "Maximum execution time of 30 seconds exceeded line number where this code is placed fgets($fp, 128), i have check the server it seems it has sent the response as expected but i am not getting why i m unable to get response.following the code using for socket connection and reading data. functon scoket_connection() { $fp = fsockopen(CLIENT_HOST,CLIENT_PORT, $errno, $errstr); fwrite($fp,$packet); $msg = fgets($fp, 128); fclose($fp) return $msg; } any idea???

    Read the article

  • Function argument treated as undeclared

    - by Mikulas Dite
    I've prepared this simple example which is not working for me #include <stdio.h> #include <stdlib.h> FILE *fp; char filename[] = "damy.txt"; void echo (char[] text) { fp = fopen(filename, "a"); fwrite(text, 1, strlen(text), fp); fclose(fp); printf(text); } int main () { echo("foo bar"); return 0; } It's supposed to write both to command window and to file. However, this gives compilation error - the text used in echo() is not declared. Does c need another declaration of the variable?

    Read the article

  • Optimizing memory usage and changing file contents with PHP

    - by errata
    In a function like this function download($file_source, $file_target) { $rh = fopen($file_source, 'rb'); $wh = fopen($file_target, 'wb'); if (!$rh || !$wh) { return false; } while (!feof($rh)) { if (fwrite($wh, fread($rh, 1024)) === FALSE) { return false; } } fclose($rh); fclose($wh); return true; } what is the best way to rewrite last few bytes of a file with my custom string? Thanks!

    Read the article

  • Internet Explorer doesn't update file

    - by Leandro
    Hi! I'm using AJAX with PHP to read from a file and update the div's innerHTML. It works on Chrome and Firefox, but not in Internet Explorer. I tried to use: But I think it is useless, since I'm not refreshing the page. if(!$newMsg || $newMsg == "") { // only reading from the file // do nothing } else { $fileData .= "$newMsg"; fwrite($fileHandler, "$newMsg"); } fclose($fileHandler); echo $fileData; Interesting that when it enters the "else" block, it shows the file's content updated. But when it enters the "if" block, it shows the old content.

    Read the article

  • PHP display progress messages on the fly

    - by XaviEsteve
    Hi everyone, I am working in a tool in PHP that processes a lot of data and takes a while to finish. I would like to keep the user updated with what is going on and the current task processed. What is in your opinion the best way to do it? I've got some ideas but can't decide for the most effective one: The old way: execute a small part of the script and display a page to the user with a Meta Redirect or a JavaScript timer to send a request to continue the script (like /script.php?step=2). Sending AJAX requests constantly to read a server file that PHP keeps updating through fwrite(). Same as above but PHP updates a field in the database instead of saving a file. Does any of those sound good? Any ideas? Thanks!

    Read the article

  • Having trouble getting GET variables from url.

    - by mchl
    Hey everyone, I'm having trouble with this algorithm to extract the get variables from a url and print them each on a new line like: x=y z=hello etc. but instead it prints a seemingly random section of the url with no newlines to the file. There must be a logic error of some kind but i just can't spot it. for(i_m=0;i_m<len_m;i_m++) { if(var_m[i_m]=='&') { fwrite(var_m+offset_m, 1, amp_m, echo_out); fputc('\n',echo_out); offset_m+=amp_m; amp_m=0; } amp_m++; } any help appreciated.

    Read the article

  • jQuery/JSON/PHP failing

    - by user730936
    I am trying to call a php script that accepts JSON data, writes it into a file and returns simple text response using jQuery/AJAX call. jQuery code : $("input.callphp").click(function() { var url_file = myurl"; $.ajax({type : "POST", url : url_file, data : {'puzzle': 'Reset!'}, success : function(data){ alert("Success: " + data); }, error : function (data) { alert("Error: " + data); }, dataType : 'text' }); }); PHP Code : <?php $thefile = "new.json"; /* Our filename as defined earlier */ $towrite = $_POST["puzzle"]; /* What we'll write to the file */ $openedfile = fopen($thefile, "w"); fwrite($openedfile, $towrite); fclose($openedfile); echo "<br> <br>".$towrite; ?> However, the call is never a success and always gives an error with an alert "Error : [Object object]".

    Read the article

  • Reading a bmp file and inverting it in C

    - by user1763396
    I have an assignment that deals with reading a bmp file into memory, inverts the pixels, and then saves the inverted image to a new file. From this description it seems fairly easy, however I don't think my professor did a great job in explaining the necessary steps to go about doing so. He taught us about fread and fwrite but there is so much more. Can anyone explain the process in going about this problem (I'm no looking for a direct answer just an explanation). Here is the link to the problem's description: https://engineering.purdue.edu/OOSD/F2012/Exercises/ex5.html Thanks in advance for any sort of help. NOTE: I actually have looked into this problem but since I don't have a good standing on this info it's not quite "clicking".

    Read the article

  • fmod getWaveData() export to WAVE file help (C++)

    - by eddietree
    I am trying to export the current sound that is being played by the FMOD::System into a WAVE file by calling getWaveData(). I have the header of the wave file correct, and currently trying to write to the wave file each frame like so: const unsigned int samplesPerSec = 48000; const unsigned int fps = 60; const int numSamples = samplesPerSec / fps; float data[2][numSamples]; short conversion[numSamples*2]; m_fmodsys->getWaveData( &data[0][0], numSamples, 0 ); // left channel m_fmodsys->getWaveData( &data[1][0], numSamples, 1 ); // right channel int littleEndian = IsLittleEndian(); for ( int i = 0; i < numSamples; ++i ) { // left channel float coeff_left = data[0][i]; short val_left = (short)(coeff_left * 0x7FFF); // right channel float coeff_right = data[1][i]; short val_right = (short)(coeff_right * 0x7FFF); // handle endianness if ( !littleEndian ) { val_left = ((val_left & 0xff) << 8) | (val_left >> 8); val_right = ((val_right & 0xff) << 8) | (val_right >> 8); } conversion[i*2+0] = val_left; conversion[i*2+1] = val_right; } fwrite((void*)&conversion[0], sizeof(conversion[0]), numSamples*2, m_fh); m_dataLength += sizeof(conversion); Currently, the timing of the sound is correct, but the sample seems clipped way harshly. More specifically, I am outputting four beats in time. When I playback the wave-file, the beats timing is correct but it just sounds way fuzzy and clipped. Am I doing something wrong with my calculation? I am exporting in 16-bits, two channels. Thanks in advance! :) Reference (WAVE file format): http://www.sonicspot.com/guide/wavefiles.html

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >