Search Results

Search found 616 results on 25 pages for 'fopen'.

Page 7/25 | < Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >

  • Tinyurl API Example - Am i doing it right :D

    - by Paul Weber
    Hi ... we use super-long Hashes for the Registration of new Users in our Application. The Problem is that these Hashes break in some Email Clients - making the Links unusable. I tried implementing the Tinyurl - API, with a simple Call, but i think it times out sometimes ... sometimes the mail does not reach the user. I updated the Code, but now the URL is never converted. Is Tinyurl really so slow or am i doing something wrong? (I mean hey, 5 Seconds is much in this Times) Can anybody recommend me a more reliable service? All my Fault, forgot a false in the fopen. But i will leave this sample of code here, because i often see this sample, wich i think does not work very reliable: return file_get_contents('http://tinyurl.com/api-create.php?url='.$u); This is the - i think fully working sample. I would like to hear about Improvements. static function gettinyurl( $url ) { $context = stream_context_create( array( 'http' => array( 'timeout' => 5 // 5 Seconds should be enough ) ) ); // get tiny url via api-create.php $fp = fopen( 'http://tinyurl.com/api-create.php?url='.$url, 'r', $context); // open (read) api-create.php with long url as get parameter if( $fp ) { // check if open was ok $tinyurl = fgets( $fp ); // read response if( $tinyurl && !empty($tinyurl) ) // check if response is ok $url = $tinyurl; // set response as url fclose( $fp ); // close connection } // return return $url; // return (tiny) url }

    Read the article

  • Warning in image_graphviz

    - by garcon1986
    Hello, I have got a warning in image_graphviz, i have viewed a post, who has a similar error. I have installed pear image_graphviz package(Image_GraphViz-1.2.1), I also installed graphviz.msi(Graphviz2.25.msi) in windows(But i don't know if does something with image_graphviz and if it does have some effects when i use image_graphviz). Do i need to do something else? Here is my code from pear image_graphviz site. <?php require_once 'Image/GraphViz.php'; error_reporting(E_ALL ^ E_NOTICE); //Added E_NOTICE $gv = new Image_GraphViz(); $gv->addEdge(array('wake up' => 'visit bathroom')); $gv->addEdge(array('visit bathroom' => 'make coffee')); $gv->image(); ?> This is the warning: Warning: fopen(C:\WINDOWS\Temp\gra50.tmp.svg) [function.fopen]: failed to open stream: No such file or directory in C:\wamp\bin\php\php5.3.0\PEAR\Image\GraphViz.php on line 210 Notice: Undefined variable: data in C:\wamp\bin\php\php5.3.0\PEAR\Image\GraphViz.php on line 218 Thanks Pekka Gaiser, I used error_reporting(E_ALL ^ E_NOTICE);. I don't know how to change the temp directory, but c:/windows/temp exists in my computer. I haven't solve the problem. Thanks all for advice.

    Read the article

  • mEncrypt/Decrypt binary mp3 with mcrypt, missing mimetype

    - by Jeremy Dicaire
    I have a script that read a mp3 file and encrypt it, I want to be able to decrypt this file and convert it to base64 so it can play in html5. Key 1 will be stored on the page and static, key2 will be unique for each file, for testing I used: $key1 = md5(time()); $key2 = md5($key1.time()); Here is my encode php code : //Get file content $file = file_get_contents('test.mp3'); //Encrypt file $Encrypt = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key1, $file, MCRYPT_MODE_CBC, $key2); $Encrypt = trim(base64_encode($Encrypt)); //Create new file $fileE = "test.mp3e"; $fileE = fopen($file64, 'w') or die("can't open file"); //Put crypted content fwrite($fileE, $Encrypt); //Close file fclose($fileE); Here is the code that doesnt work (decoded file is same size, but no mimetype): //Get file content $fileE = file_get_contents('test.mp3e'); //Decode $fileDecoded = base64_decode($fileE); //Decrypt file $Decrypt = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key1, $fileDecoded, MCRYPT_MODE_CBC, $key2); $Decrypt = trim($Decrypt); //Create new file $file = "test.mp3"; $file = fopen($file, 'w') or die("can't open file"); //Put crypted content fwrite($file, $Decrypt); //Close file fclose($file);

    Read the article

  • warning: assignment makes pointer from integer without a cast

    - by FILIaS
    Im new in programming c with arrays and files. Im just trying to run the following code but i get warnings like that: warning: assignment makes pointer from integer without a cast Any help? It might be silly... but I cant find what's wrong. FILE *fp; FILE *cw; char filename_game[40],filename_words[40]; int main() { while(1) { /* Input filenames. */ printf("\n Enter the name of the file with the cryptwords array: \n"); gets(filename_game); printf("\n Give the name of the file with crypted words:\n"); gets(filename_words); /* Try to open the file with the game */ if (fp=fopen("crypt.txt","r")!=NULL) { printf("\n Successful opening %s \n",filename_game); fclose(fp); puts("\n Enter x to exit,any other to continue! \n "); if ( (getc(stdin))=='x') break; else continue; } else { fprintf(stderr,"ERROR!%s \n",filename_game); puts("\n Enter x to exit,any other to continue! \n"); if (getc(stdin)=='x') break; else continue; } /* Try to open the file with the names. */ if (cw=fopen("words.txt","r")!=NULL) { printf("\n Successful opening %s \n",filename_words); fclose(cw); puts("\n Enter x to exit,any other to continue \n "); if ( (getc(stdin))=='x') break; else continue; } else { fprintf(stderr,"ERROR!%s \n",filename_words); puts("\n Enter x to exit,any other to continue! \n"); if (getc(stdin)=='x') break; else continue; } } return 0; }

    Read the article

  • speed string search in PHP

    - by Marc
    Hi! I have a 1.2GB file that contains a one line string. What I need is to search the entire file to find the position of an another string (currently I have a list of strings to search). The way what I'm doing it now is opening the big file and move a pointer throught 4Kb blocks, then moving the pointer X positions back in the file and get 4Kb more. My problem is that a bigger string to search, a bigger time he take to got it. Can you give me some ideas to optimize the script to get better search times? this is my implementation: function busca($inici){ $limit = 4096; $big_one = fopen('big_one.txt','r'); $options = fopen('options.txt','r'); while(!feof($options)){ $search = trim(fgets($options)); $retro = strlen($search);//maybe setting this position absolute? (like 12 or 15) $punter = 0; while(!feof($big_one)){ $ara = fgets($big_one,$limit); $pos = strpos($ara,$search); $ok_pos = $pos + $punter; if($pos !== false){ echo "$pos - $punter - $search : $ok_pos <br>"; break; } $punter += $limit - $retro; fseek($big_one,$punter); } fseek($big_one,0); } } Thanks in advance!

    Read the article

  • uploading image & getting back from database

    - by Anup Prakash
    Putting a set of code which is pushing image to database and fetching back from database: <!-- <?php error_reporting(0); // Connect to database $errmsg = ""; if (! @mysql_connect("localhost","root","")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("test"); $q = <<<CREATE create table image ( pid int primary key not null auto_increment, title text, imgdata longblob, friend text) CREATE; @mysql_query($q); // Insert any new image into database if (isset($_POST['submit'])) { move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img"))); if (strlen($instr) < 149000) { $image_query="insert into image (title, imgdata,friend) values (\"". $_REQUEST['title']. "\", \"". $image. "\",'".$_REQUEST['friend']."')"; mysql_query ($image_query) or die("query error"); } else { $errmsg = "Too large!"; } $resultbytes=''; // Find out about latest image $query = "select * from image where pid=1"; $result = @mysql_query("$query"); $resultrow = @mysql_fetch_assoc($result); $gotten = @mysql_query("select * from image order by pid desc limit 1"); if ($row = @mysql_fetch_assoc($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata]; $resultbytes = $row[imgdata]; $friend=$row[friend]; } else { $errmsg = "There is no image in the database yet"; $title = "no database image available"; // Put up a picture of our training centre $instr = fopen("../wellimg/ctco.jpg","rb"); $bytes = fread($instr,filesize("../wellimg/ctco.jpg")); } if ($resultbytes!='') { echo $resultbytes; } } ?> <html> <head> <title>Upload an image to a database</title> </head> <body bgcolor="#FFFF66"> <form enctype="multipart/form-data" name="file_upload" method="post"> <center> <div id="image" align="center"> <h2>Heres the latest picture</h2> <font color=red><?php echo $errmsg; ?></font> <b><?php echo $title ?></center> </div> <hr> <h2>Please upload a new picture and title</h2> <table align="center"> <tr> <td>Select image to upload: </td> <td><input type="file" name="imagefile"></td> </tr> <tr> <td>Enter the title for picture: </td> <td><input type="text" name="title"></td> </tr> <tr> <td>Enter your friend's name:</td> <td><input type="text" name="friend"></td> </tr> <tr> <td><input type="submit" name="submit" value="submit"></td> <td></td> </tr> </table> </form> </body> </html> --> Above set of code has one problem. The problem is whenever i pressing the "submit" button. It is just displaying the image on a page. But it is leaving all the html codes. even any new line message after the // Printing image on browser echo $resultbytes; //************************// So, for this i put this set of code in html tag: This is other sample code: <!-- <?php error_reporting(0); // Connect to database $errmsg = ""; if (! @mysql_connect("localhost","root","")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("test"); $q = <<<CREATE create table image ( pid int primary key not null auto_increment, title text, imgdata longblob, friend text) CREATE; @mysql_query($q); // Insert any new image into database if (isset($_POST['submit'])) { move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img"); $instr = fopen("latest.img","rb"); $image = addslashes(fread($instr,filesize("latest.img"))); if (strlen($instr) < 149000) { $image_query="insert into image (title, imgdata,friend) values (\"". $_REQUEST['title']. "\", \"". $image. "\",'".$_REQUEST['friend']."')"; mysql_query ($image_query) or die("query error"); } else { $errmsg = "Too large!"; } $resultbytes=''; // Find out about latest image $query = "select * from image where pid=1"; $result = @mysql_query("$query"); $resultrow = @mysql_fetch_assoc($result); $gotten = @mysql_query("select * from image order by pid desc limit 1"); if ($row = @mysql_fetch_assoc($gotten)) { $title = htmlspecialchars($row[title]); $bytes = $row[imgdata]; $resultbytes = $row[imgdata]; $friend=$row[friend]; } else { $errmsg = "There is no image in the database yet"; $title = "no database image available"; // Put up a picture of our training centre $instr = fopen("../wellimg/ctco.jpg","rb"); $bytes = fread($instr,filesize("../wellimg/ctco.jpg")); } } ?> <html> <head> <title>Upload an image to a database</title> </head> <body bgcolor="#FFFF66"> <form enctype="multipart/form-data" name="file_upload" method="post"> <center> <div id="image" align="center"> <h2>Heres the latest picture</h2> <?php if ($resultbytes!='') { // Printing image on browser echo $resultbytes; } ?> <font color=red><?php echo $errmsg; ?></font> <b><?php echo $title ?></center> </div> <hr> <h2>Please upload a new picture and title</h2> <table align="center"> <tr> <td>Select image to upload: </td> <td><input type="file" name="imagefile"></td> </tr> <tr> <td>Enter the title for picture: </td> <td><input type="text" name="title"></td> </tr> <tr> <td>Enter your friend's name:</td> <td><input type="text" name="friend"></td> </tr> <tr> <td><input type="submit" name="submit" value="submit"></td> <td></td> </tr> </table> </form> </body> </html> --> ** But in this It is showing the image in format of special charaters and digits. 1) So, Please help me to print the image with some HTML code. So that i can print it in my form to display the image. 2) Is there any way to convert the database image into real image, so that i can store it into my hard-disk and call it from tag? Please help me.

    Read the article

  • error in finding out the lexems and no of lines of a text file in C

    - by mekasperasky
    #include<stdio.h> #include<ctype.h> #include<string.h> int main() { int i=0,j,k,lines_count[2]={1,1},operand_count[2]={0},operator_count[2]={0},uoperator_count[2]={0},control_count[2]={0,0},cl[13]={0},variable_dec[2]={0,0},l,p[2]={0},ct,variable_used[2]={0,0},constant_count[2],s[2]={0},t[2]={0}; char a,b[100],c[100]; char d[100]={0}; j=30; FILE *fp1[2],*fp2; fp1[0]=fopen("program1.txt","r"); fp1[1]=fopen("program2.txt","r"); //the source file is opened in read only mode which will passed through the lexer fp2=fopen("ccv1ouput.txt","wb"); //now lets remove all the white spaces and store the rest of the words in a file if(fp1[0]==NULL) { perror("failed to open program1.txt"); //return EXIT_FAILURE; } if(fp1[1]==NULL) { perror("failed to open program2.txt"); //return EXIT_FAILURE; } i=0; k=0; ct=0; while(ct!=2) { while(!feof(fp1[ct])) { a=fgetc(fp1[ct]); if(a!=' '&&a!='\n') { if (!isalpha(a) && !isdigit(a)) { switch(a) { case '+':{ i=0; cl[0]=1; operator_count[ct]=operator_count[ct]+1;break;} case '-':{ cl[1]=1; operator_count[ct]=operator_count[ct]+1;i=0;break;} case '*':{ cl[2]=1; operator_count[ct]=operator_count[ct]+1;i=0;break;} case '/':{ cl[3]=1; operator_count[ct]=operator_count[ct]+1;i=0;break;} case '=':{a=fgetc(fp1[ct]); if (a=='='){cl[4]=1; operator_count[ct]=operator_count[ct]+1; operand_count[ct]=operand_count[ct]+1;} else { cl[5]=1; operator_count[ct]=operator_count[ct]+1; operand_count[ct]=operand_count[ct]+1; ungetc(1,fp1[ct]); } break;} case '%':{ cl[6]=1; operator_count[ct]=operator_count[ct]+1;i=0;break;} case '<':{ a=fgetc(fp1[ct]); if (a=='=') {cl[7]=1; operator_count[ct]=operator_count[ct]+1;} else { cl[8]=1; operator_count[ct]=operator_count[ct]+1; ungetc(1,fp1[ct]); } break; } case '>':{ ; a=fgetc(fp1[ct]); if (a=='='){cl[9]=1; operator_count[ct]=operator_count[ct]+1;} else { cl[10]=1; operator_count[ct]=operator_count[ct]+1; ungetc(1,fp1[ct]); } break;} case '&':{ cl[11]=1; a=fgetc(fp1[ct]); operator_count[ct]=operator_count[ct]+1; operand_count[ct]=operand_count[ct]+1; variable_used[ct]=variable_used[ct]-1; break; } case '|':{ cl[12]=1; a=fgetc(fp1[ct]); operator_count[ct]=operator_count[ct]+1; operand_count[ct]=operand_count[ct]+1; variable_used[ct]=variable_used[ct]-1; break; } case '#':{ while(a!='\n') { a=fgetc(fp1[ct]); } } } } else { d[i]=a; i=i+1; k=k+1; } } else { //printf("%s \n",d); if((strcmp(d,"if")==0)){ memset ( d, 0, 100 ); i=0; control_count[ct]=control_count[ct]+1; } else if(strcmp(d,"then")==0){ i=0;memset ( d, 0, 100 );control_count[ct]=control_count[ct]+1;} else if(strcmp(d,"else")==0){ i=0;memset ( d, 0, 100 );control_count[ct]=control_count[ct]+1;} else if(strcmp(d,"while")==0){ i=0;memset ( d, 0, 100 );control_count[ct]=control_count[ct]+1;} else if(strcmp(d,"int")==0){ while(a != '\n') { a=fgetc(fp1[ct]); if (isalpha(a) ) variable_dec[ct]=variable_dec[ct]+1; } memset ( d, 0, 100 ); lines_count[ct]=lines_count[ct]+1; } else if(strcmp(d,"char")==0){while(a != '\n') { a=fgetc(fp1[ct]); if (isalpha(a) ) variable_dec[ct]=variable_dec[ct]+1; } memset ( d, 0, 100 ); lines_count[ct]=lines_count[ct]+1; } else if(strcmp(d,"float")==0){while(a != '\n') { a=fgetc(fp1[ct]); if (isalpha(a) ) variable_dec[ct]=variable_dec[ct]+1; } memset ( d, 0, 100 ); lines_count[ct]=lines_count[ct]+1; } else if(strcmp(d,"printf")==0){while(a!='\n') a=fgetc(fp1[ct]); memset(d,0,100); } else if(strcmp(d,"scanf")==0){while(a!='\n') a=fgetc(fp1[ct]); memset(d,0,100);} else if (isdigit(d[i-1])) { memset ( d, 0, 100 ); i=0; constant_count[ct]=constant_count[ct]+1; operand_count[ct]=operand_count[ct]+1; } else if (isalpha(d[i-1]) && strcmp(d,"int")!=0 && strcmp(d,"char")!=0 && strcmp(d,"float")!=0 && (strcmp(d,"if")!=0) && strcmp(d,"then")!=0 && strcmp(d,"else")!=0 && strcmp(d,"while")!=0 && strcmp(d,"printf")!=0 && strcmp(d,"scanf")!=0) { memset ( d, 0, 100 ); i=0; operand_count[ct]=operand_count[ct]+1; } else if(a=='\n') { lines_count[ct]=lines_count[ct]+1; memset ( d, 0, 100 ); } } } fclose(fp1[ct]); operand_count[ct]=operand_count[ct]-5; variable_used[0]=operand_count[0]-constant_count[0]; variable_used[1]=operand_count[1]-constant_count[1]; for(j=0;j<12;j++) uoperator_count[ct]=uoperator_count[ct]+cl[j]; fprintf(fp2,"\n statistics of program %d",ct+1); fprintf(fp2,"\n the no of lines ---> %d",lines_count[ct]); fprintf(fp2,"\n the no of operands --->%d",operand_count[ct]); fprintf(fp2,"\n the no of operator --->%d",operator_count[ct]); fprintf(fp2,"\n the no of control statments --->%d",control_count[ct]); fprintf(fp2,"\n the no of unique operators --->%d",uoperator_count[ct]); fprintf(fp2,"\n the no of variables declared--->%d",variable_dec[ct]); fprintf(fp2,"\n the no of variables used--->%d",variable_used[ct]); fprintf(fp2,"\n ---------------------------------"); fprintf(fp2,"\n \t \t \t"); ct=ct+1; } t[0]=lines_count[0]+control_count[0]+uoperator_count[0]; t[1]=lines_count[1]+control_count[1]+uoperator_count[1]; s[0]=operator_count[0]+operand_count[0]+variable_dec[0]+variable_used[0]; s[1]=operator_count[1]+operand_count[1]+variable_dec[1]+variable_used[1]; fprintf(fp2,"\n the time complexity of program 1 is %d",t[0]); fprintf(fp2,"\n the time complexity of program 2 is %d",t[1]); fprintf(fp2,"\n the space complexity of program 1 is %d",s[0]); fprintf(fp2,"\n the space complexity of program 2 is %d",s[1]); if((t[0]>t[1]) && (s[0] >s[1])) fprintf(fp2,"\n the efficiency of program 2 is greater than program 1"); else if(t[0]<t[1] && s[0] < s[1]) fprintf(fp2,"\n the efficiency of program 1 is greater than program 2 " ); else if (t[0]+s[0] > t[1]+s[1]) fprintf(fp2,"\n the efficiency of program 1 is greater than program 2"); else if (t[0]+s[0] < t[1]+s[1]) fprintf(fp2,"\n the efficiency of program 2 is greater than program 1"); else if (t[0]+s[0] == t[1]+s[1]) fprintf(fp2,"\n the efficiency of program 1 is equal to that of program 2"); fclose(fp2); return 0; } this code basically compares two c codes and finds out the no. of variables declared , used , no. of control statements , no. of lines and no. of unique operators , and operands , so as to find out the time complexity and space complexity of of the two programs given in the text file program1.txt and program2.txt ... Lets say program1.txt is this #include<stdio.h> #include<math.h> int main () { FILE *fp; fp=fopen("output.txt","w"); long double t,y=0,x=0,e=5,f=1,w=1; for (t=0;t<10;t=t+0.01) { //if (isnan(y) || isinf(y)) //break; fprintf(fp,"%ld\t%ld\n",y,x); y = y + ((e*(1 - (x*x))*y) - x + f*cos(w*0.1))*0.1; x = x + y*0.1; } fclose(fp); return (0); } i havent indented it as its just a text file . But my output is totally faulty . Its not able to find the any of the ouput that i need . Where is the bug in this ? I am not able to figure out as the algorithm looks fine .

    Read the article

  • leak in fgets when assigning to buffer

    - by monkeyking
    I'm having problems understanding why following code leaks in one case, and not in the other case. The difference is while(NULL!=fgets(buffer,length,file))//doesnt leak while(NULL!=(buffer=fgets(buffer,length,file))//leaks I thought it would be the same. Full code below. #include <stdio.h> #include <stdlib.h> #define LENS 10000 void no_leak(const char* argv){ char *buffer = (char *) malloc(LENS); FILE *fp=fopen(argv,"r"); while(NULL!=fgets(buffer,LENS,fp)){ fprintf(stderr,"%s",buffer); } fclose(fp); fprintf(stderr,"%s\n",buffer); free(buffer); } void with_leak(const char* argv){ char *buffer = (char *) malloc(LENS); FILE *fp=fopen(argv,"r"); while(NULL!=(buffer=fgets(buffer,LENS,fp))){ fprintf(stderr,"%s",buffer); } fclose(fp); fprintf(stderr,"%s\n",buffer); free(buffer); }

    Read the article

  • What can i use to journal writes to file system

    - by Dmitry
    Hello, all I need to track all writes to files in order to have synchronized version of files on different place (server or just other directory, not considerable). Let it: all files located in same directory feel free to create some system files (e.g. SomeFileName.Ext~temp-data) no one have concurrent access to synced directory; nobody spoil ours meta-files or change real-files before we do postponed writes (like a commits) do not to care recovering "local" changes in case of crash; system can just rolled back to state of "server" by simple copy from it significant to have it transparent to use (so programmer must just call ordinary fopen(), read(), write()) It must be guaranteed that copy of files which "server" have is consistent. That is whole files scope existed in some moment of time. They may be sufficiently outdated but it must be fair snapshot of all files at some time. As i understand i should overload writing logic to collect data in order sent changes to "server". For example writing to temporary File~tmp. And so i have to overload reads in order program could read actual data of file. It would be great if you suggest some existing library (java or c++, it is unimportant) or solution (VCS customizing?). Or give hints how should i write it by myself. edit: After some reading i have more precision requirements: I need COW (Copy-on-write) wrapper for fopen(),fwrite(),.. or interceptor (hook) WriteFile() and other FS api system calls. Log-structured file system in userspace would be a alternative too.

    Read the article

  • php how to serialize array of objects?

    - by hequ
    Hello, I have small class called 'Call' and I need to store these calls into a flat file. I've made another class called 'CallStorage' which contains an array where I put these calls into. My problem is that I would like to store this array to disk so I could later read it back and get the calls from that array. I've tried to achieve this using serialize() and unserialize() but these seems to act somehow strange and part of the information gets lost. This is what I'm doing: //write array to disk $filename = $path . 'calls-' . $today; $serialized = serialize($this->array); $fp = fopen($filename, 'a'); fwrite($fp, $serialized); fclose($fp); //read array from serialized file $filename = $path . 'calls-' . $today; if (file_exists($filename)) { $handle = fopen($filename, 'r'); $contents = fread($handle, filesize($filename)); fclose($handle); $unserialized = unserialize($contents); $this->setArray($unserialized); } Can someone see what I'm doing wrong, or what. I've also tried to serialize and write arrays that contains plain strings. I didn't manage to get that working either.. I have a Java background so I just can't see why I couldn't just write an array to disk if it's serialized. :)

    Read the article

  • download file, without saving in server

    - by lolalola
    Hi, Or possible for users to download the file without saving it on the server? I am getting data from the database, and I want to save them .doc (MS Word) file. if(isset($_POST['save'])) { $file = "new_file2.doc"; $stringData = "Text text text text...."; //This data put in new Word file $fh = fopen($file, 'w'); fwrite($fh, $stringData); fclose($fh); header('Content-Description: File Transfer'); header('Content-type: application/msword'); header('Content-Disposition: attachment; filename="'.$file.'"'); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); unlink($file); exit; } How should the code look like without this: " $fh = fopen($file, 'w'); fwrite($fh, $stringData); fclose($fh);" and this "unlink($file);" I hope to understand what I need enter code here

    Read the article

  • Wordpress paths issue

    - by Martin
    I have set a crawler up in wordpress which grabs stocks data and writes to file which when a user enters a symbol/ticker the variable is read and if it matches the data of a previous crawl for that particular companies data will echo the text file on page, if no data is found the crawler then sets off grabs it and writes to file to save for the next time that symbol is used. The problem im having is that everything works groovey apart from one thing, when the content is written to file it saves it in the WP root and not inside a subfolder of the theme, basicaly this means that root becomes untidy very quickly and also should the theme be used on another site then its not practical as some important info is missing. I have tried bloginfo and absolute both return the same failure. This is the code i am using to write to file, like i say it works apart from writing the file into root. <?php $CompDetails = "http://www.devserverurl.com/mattv1/wp-content/themes/stocks/tools/modules/Stock_Quote/company_details/$Symbol.txt"; if (file_exists($CompDetails)) {} else { include ('crawler_file.php'); $html = file_get_html("http://targeturl.com/research/stocks/snapshot/snapshot.asp?ticker=$Symbol:US"); $es = $html->find('div[class="detailsDataContainerLt"]'); $tickerdetails = ("$es[0]"); $FileHandle2 = fopen($CompDetails, 'w') or die("can't open file"); fwrite($FileHandle2, $tickerdetails); fclose($FileHandle2); } ?> edit below, have also tried this and the same happens as above <?php if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stocks/tools/modules/Stock_Quote/company_details/$Symbol.txt")) {} else { include ('crawler_file.php'); $html = file_get_html("http://targeturl.com/research/stocks/snapshot/snapshot.asp?ticker=$Symbol:US"); $es = $html->find('div[class="detailsDataContainerLt"]'); $tickerdetails = ("$es[0]"); $FileHandle2 = fopen($_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/stocks/tools/modules/Stock_Quote/company_details/$Symbol.txt", 'w') or die("can't open file"); fwrite($FileHandle2, $tickerdetails); fclose($FileHandle2); } ?>

    Read the article

  • Convert this code from C++ to C#

    - by Alhariri
    please any one convert this code from c++ to c# beacuse i dont know how to read from file in c++ please help me int DoEnDe(int c) { SDES S(key); int i,n; n=10; //Number of Rounds unsigned char ch; FILE *fp; FILE *ft; fp=fopen(tfname,"w"); ft=fopen(sfname,"r"); if (fp==NULL) { printf("\nTarget File not opened SORRY"); getch(); fclose(fp); return(0); } if (ft==NULL) { printf("\nSource File not opened SORRY"); getch(); fclose(ft); return(0); } while (fread(&ch,1,1,ft)==1) { S.OUTPUT=ch; for (i=0;i<n;i++) { if (c==1) S.DES_Encryption(S.OUTPUT); if (c==2) S.DES_Decryption(S.OUTPUT); } fwrite(&S.OUTPUT,1,1,fp); } printf("\nCompleted!!!!!"); getch(); fclose(fp); fclose(ft); return(1); }

    Read the article

  • PHP unlink OR rewrite own/current file by itself

    - by Email
    Hi Task: Cut or erase a file after first walk-through. i have an install file called "index.php" which creates another php file. <? /* here some code*/ $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = "<?php \n echo 'hallo, *very very long text*'; \n ?>"; fwrite($fh, $stringData); /*herecut"/ /*here some code */ after the creation of the new file this file is called and i intent to erase the filecreation call since it is very long and only needed on first install. i therefor add to the above code echo 'hallo, *very very long text*'; \n ***$new= file_get_contents('index.php'); \n $findme = 'habanot'; $pos = strpos($new, $findme); if ($pos === false) { $marker='herecut';\n $new=strstr($new,$marker);\n $new='<?php \n /*habanot*/\n'.$new;\n $fh = fopen('index.php', 'w') or die 'cant open file'); $stringData = $new; fwrite($fh, $stringData); fclose($fh);*** ?>"; fwrite($fh, $stringData);]} Isnt there an easier way or a function to modify the current file or even "self destroy" a file after first call? Regards

    Read the article

  • suppress error using fread()

    - by Mikey1980
    I wrote a script for screen pops from our soft phone that locates a directory listing for the caller but occasionally they get "Can't read input stream" and the rest of the script quits. Does anyone have any suggestions on how to suppress error the error message and allow the rest of the script to run? Thanks! $i=0; $open = fopen("http://www.411.ca/whitepages/?n=".$_GET['phone'], "r"); $read = fread($open, 9024); fclose($open); eregi("'/(.*)';",$read,$got); $tv = ereg_replace('[[:blank:]]',' ',$got[1]); $url = "http://www.411.ca/".$tv; while ($name=="unknown" && $i < 15) { ## try 15 times before giving up $file = @ fopen($fn=$url,"r") or die ("Can't read input stream"); $text = fread($file,16384); if (preg_match('/"name">(.*?)<\/div>/is',$text,$found)) { $name = $found[1]; } if (preg_match('/"phone">(.*?)<\/div>/is',$text,$found)) { $phone = $found[1]; } if (preg_match('/"address">(.*?)<\/div>/is',$text,$found)) { $address = $found[1]; } fclose($file); $i++; }

    Read the article

  • c++ figuring out memory layout of members programatically

    - by anon
    Suppose in one program, I'm given: class Foo { int x; double y; char z; }; class Bar { Foo f1; int t; Foo f2; }; int main() { Bar b; bar.f1.z = 'h'; bar.f2.z = 'w'; ... some crap setting value of b; FILE *f = fopen("dump", "wb"); // c-style file fwrite(&b, sizeof(Bar), 1, f); } Suppose in another program, I have: int main() { File *f = fopen("dump", "rb"); std::string Foo = "int x; double y; char z;"; std::string Bar = "Foo f1; int t; Foo f2;"; // now, given this is it possible to read out // the value of bar.f1.z and bar.f2.z set earlier? } WHat I'm asking is: given I have the types of a class, can I figure out how C++ lays it out?

    Read the article

  • How to Save data in txt file in MATLAB

    - by Jessy
    I have 3 txt files s1.txt, s2.txt, s3.txt.Each have the same format and number of data.I want to combine only the second column of each of the 3 files into one file. Before I combine the data, I sorted it according to the 1st column: UnSorted file: s1.txt s2.txt s3.txt 1 23 2 33 3 22 4 32 4 32 2 11 5 22 1 10 5 28 2 55 8 11 7 11 Sorted file: s1.txt s2.txt s3.txt 1 23 1 10 2 11 2 55 2 33 3 22 4 32 4 32 5 28 5 22 8 11 7 11 Here is the code I have so far: BaseFile ='s' n=3 fid=fopen('RT.txt','w'); for i=1:n %Open each file consecutively d(i)=fopen([BaseFile num2str(i)'.txt']); %read data from file A=textscan(d(i),'%f%f') a=A{1} b=A{2} ab=[a,b]; %sort the data according to the 1st column B=sortrows(ab,1); %delete the 1st column after being sorted B(:,1)=[] %write to a new file fprintf(fid,'%d\n',B'); %close (d(i)); end fclose(fid); How can I get the output in the new txt file in this format? 23 10 11 55 33 22 32 32 28 22 11 11 instead of this format? 23 55 32 22 10 33 32 11 11 22 28 11

    Read the article

  • Why can’t PHP script write a file on server 2008 via command line or task scheduler?

    - by rg89
    I created a question on serverfault.com, and it was recommended that I ask here. http://serverfault.com/questions/140669/why-cant-php-script-write-a-file-on-server-2008-via-command-line-or-task-schedul I have a PHP script. It runs well when I use a browser. It writes an XML file in the same directory. The script takes ~60 seconds to run, and the resulting XML file is ~16 MB. I am running PHP 5.2.13 via FastCGI on Windows Server Web edition SP1 64 bit. The code pulls inventory from SQL server, runs a loop to build an XML file for a third party. I created a task in task scheduler to run c:\php5\php.exe "D:\inetpub\tools\build.php" The task scheduler shows a time lapse of about a minute, which is how long the script takes to run in a browser. No error returned, but no file created. Each time I make a change to the scheduled task properties, a user password box comes up and I enter the administrator account password. If I run this same path and argument at a command line it does not error and does not create the file. When I right click run command prompt as an administrator, the file is still not created. I get my echo statement "file published" that is after the file creation and no error is returned. I am doing a simple fopen fwrite fclose to save the contents of a php variable to a .xml file, and the file only gets created when the script is run through the browser. Here's what happens after the xml-building loop: $feedContent .= "</feed"; sqlsrv_close( $conn ); echo "<p>feed built</p>"; $feedFile = "feed.xml"; $handler = fopen($feedFile, 'w'); fwrite( $handler, $feedContent ); fclose( $handler ); echo "<p>file published</p>"; Thanks

    Read the article

  • Merge n files using a C program

    - by Amal
    I am writing a download Accelerator. So I download a file from the webserver into n parts. Now I want to merge the files into 1 single file. So I use the following code. And the file names are in the correct order. But the output file I am getting is different from the original download file. Can you tell me where could the error be ?C int cbd_merge_files(const char** filenames, int n, const char* final_filename) { FILE* fp = fopen(final_filename, "wb"); if (fp == NULL) return 1; char buffer[4097]; for (int i = 0; i < n; ++i) { const char* fname = filenames[i]; FILE* fp_read = fopen(fname, "rb"); if (fp_read == NULL) return 1; int n; while ((n = fread(buffer, sizeof(char), 4096, fp_read))) { int k = fwrite(buffer, sizeof(char), n, fp); if (!k) return 1; } fclose(fp_read); } fclose(fp); return 0; }

    Read the article

  • unicode convertion problem

    - by bhoomi-nature
    Hai frnds i am bhoomi new to php,i am having having below problem in my coding please can you help anyone 1.first i want to open one word document which is having content and i wann to edit it 2.for that i am opening word document from the server and at that time its opening with garbage value(i thing its not converting to utf8 format) 3.wen i delete that garbage value and insert something from textarea to that file it is going to insert and next time onwords its its getting open properly. 4.actually i wann that doc file should open with english words wats there in that doc instead of garbage value..first time opening only its giving problem. i am using below code for that please do the needful $filename = 'test.doc'; if(isset($_REQUEST['Submit'])){ $somecontent = stripslashes($_POST['somecontent']); // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename) - Continue - "; fclose($handle); } else { echo "The file $filename is not writable"; } } else{ // get contents of a file into a string $handle = fopen($filename, 'r'); $somecontent = fread($handle, filesize($filename)); ? Edit file

    Read the article

  • opening word document contailning macros using textarea

    - by avani-nature
    Hai frnds i am avani here,actually 1.i amhaving one word document which contains macros i wann to open it in textarea.. 2.i am able to open the word document which is not containing macros 3.i am not able to open the document which contains macros 4.i am using below code 5.please do help me anyone i am thinking its some what impossible { //echo $aud; $filename = 'C:/xampp/htdocs/mts/sites/default/files/a.doc'; //echo $filename; if(isset($_REQUEST['Save'])){ $somecontent = stripslashes($_POST['somecontent']); // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'w')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename) - Continue - "; fclose($handle); } else { echo "The file $filename is not writable"; } } else{ // get contents of a file into a string $handle = fopen($filename, "r"); $somecontent = fread($handle, filesize($filename)); $word = new COM("word.application") or die ("Could not initialise MS Word object."); $word-Documents-Open(realpath("$filename")); // Extract content. $somecontent = (string) $word-ActiveDocument-Content; //echo $somecontent; $word-ActiveDocument-Close(false); $word-Quit(); $word = null; unset($word); fclose($handle); } ? Edit file -------- ?

    Read the article

  • Upload image from URL to FTP server using PHP

    - by user1807556
    I want to upload a picture from another site to my FTP server using PHP. Example: File to upload("http://page.mi.fu-berlin.de/krudolph/stuff/stackoverflow.png") FTP-path("pictures/") This is what I've already tried: 1 $image = file_get_contents("http://img.youtube.com/vi/Rz8KW4Tveps/1.jpg"); file_put_contents("imgfolder/imgID.jpg", $image); 2 copy('http://img.youtube.com/vi/Rz8KW4Tveps/1.jpg', 'imgfolder/imgID.jpg'); 3 <?php set_time_limit (24 * 60 * 60); if (!isset($_POST['submit'])) die(); $file = fopen ($url, "rb"); if ($file) { $newf = fopen ($newfname, "wb"); if ($newf) while(!feof($file)) { fwrite($newf, fread($file, 1024 * 2000 ), 1024 * 2000 ); } } if ($file) { fclose($file); } if ($newf) { fclose($newf); } ?> 4 http://www.teckdevil.com/php-server-to-server-transfer-script-to-remotely-transfer-files/ 5 (kinda the same as first linked) Download files directly to my server # I don't get any errors when I'm running the scripts and I have chmod the directory to 777.

    Read the article

  • error in a c code while trying to remove whitespace

    - by mekasperasky
    this code is the base of lexer , and it does the basic operation of removing the whitespaces from a source file and rewrites it into another file with each word in separate lines . But i am not able to understand why the file lext.txt not getting updated? #include<stdio.h> /* this is a lexer which recognizes constants , variables ,symbols, identifiers , functions , comments and also header files . It stores the lexemes in 3 different files . One file contains all the headers and the comments . Another file will contain all the variables , another will contain all the symbols. */ int main() { int i; char a,b[20],c; FILE *fp1,*fp2; fp1=fopen("source.txt","r"); //the source file is opened in read only mode which will passed through the lexer fp2=fopen("lext.txt","w"); //now lets remove all the white spaces and store the rest of the words in a file if(fp1==NULL) { perror("failed to open source.txt"); //return EXIT_FAILURE; } i=0; while(!feof(fp1)) { a=fgetc(fp1); if(a!="") { b[i]=a; printf("hello"); } else { b[i]='\0'; fprintf(fp2, "%.20s\n", b); i=0; continue; } i=i+1; /*Switch(a) { case EOF :return eof; case '+':sym=sym+1; case '-':sym=sym+1; case '*':sym=sym+1; case '/':sym=sym+1; case '%':sym=sym+1; case ' */ } return 0; }

    Read the article

  • Sending Images over Sockets in C

    - by Takkun
    I'm trying to send an image file through a TCP socket in C, but the image isn't being reassembled correctly on the server side. I was wondering if anyone can point out the mistake? I know that the server is receiving the correct file size and it constructs a file of that size, but it isn't an image file. Client //Get Picture Size printf("Getting Picture Size\n"); FILE *picture; picture = fopen(argv[1], "r"); int size; fseek(picture, 0, SEEK_END); size = ftell(picture); //Send Picture Size printf("Sending Picture Size\n"); write(sock, &size, sizeof(size)); //Send Picture as Byte Array printf("Sending Picture as Byte Array\n"); char send_buffer[size]; while(!feof(picture)) { fread(send_buffer, 1, sizeof(send_buffer), picture); write(sock, send_buffer, sizeof(send_buffer)); bzero(send_buffer, sizeof(send_buffer)); } Server //Read Picture Size printf("Reading Picture Size\n"); int size; read(new_sock, &size, sizeof(1)); //Read Picture Byte Array printf("Reading Picture Byte Array\n"); char p_array[size]; read(new_sock, p_array, size); //Convert it Back into Picture printf("Converting Byte Array to Picture\n"); FILE *image; image = fopen("c1.png", "w"); fwrite(p_array, 1, sizeof(p_array), image); fclose(image);

    Read the article

  • C Language: Why I cannot transfer file from server to client?

    - by user275753
    I want to ask, why I cannot transfer file from server to client? When I start to send the file from server, the client side program will have problem. So, I spend some times to check the code, But I still cannot find out the problem Can anyone point out the problem for me? thanks a lot! [client side code] include include include include include include include define SA struct sockaddr define S_PORT 5678 define MAXLEN 1000 define true 1 void errexit(const char *format, ...) { va_list args; va_start(args, format); vfprintf(stderr, format, args); va_end(args); WSACleanup(); exit(1); } int main(int argc, char *argv []) { WSADATA wsadata; SOCKET sockfd; int number,message; char outbuff[MAXLEN],inbuff[MAXLEN]; char PWD_buffer[_MAX_PATH]; struct sockaddr_in servaddr; FILE *fp; int numbytes; char buf[2048]; if (WSAStartup(MAKEWORD(2,2), &wsadata) != 0) errexit("WSAStartup failed\n"); if (argc != 2) errexit("client IPaddress"); if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET ) errexit("socket error: error number %d\n", WSAGetLastError()); memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(S_PORT); if ( (servaddr.sin_addr.s_addr = inet_addr(argv[1])) == INADDR_NONE) errexit("inet_addr error: error number %d\n", WSAGetLastError()); if (connect(sockfd, (SA *) &servaddr, sizeof(servaddr)) == SOCKET_ERROR) errexit("connect error: error number %d\n", WSAGetLastError()); if ( (fp = fopen("C:\\users\\pc\\desktop\\COPY.c", "wb")) == NULL){ perror("fopen"); exit(1); } printf("Still NO PROBLEM!\n"); //Receive file from server while(1){ numbytes = read(sockfd, buf, sizeof(buf)); printf("read %d bytes, ", numbytes); if(numbytes == 0){ printf("\n"); break; } numbytes = fwrite(buf, sizeof(char), numbytes, fp); printf("fwrite %d bytes\n", numbytes); } fclose(fp); close(sockfd); return 0; } server side code include include include include include include include include define SA struct sockaddr define S_PORT 5678 define MAXLEN 1000 void errexit(const char *format, ...) { va_list args; va_start(args, format); vfprintf(stderr, format, args); va_end(args); WSACleanup(); exit(1); } int main(int argc, char *argv []) { WSADATA wsadata; SOCKET listenfd, connfd; int number, message, numbytes; int h, i, j, alen; int nread; struct sockaddr_in servaddr, cliaddr; FILE *in_file, *out_file, *fp; char buf[4096]; if (WSAStartup(MAKEWORD(2,2), &wsadata) != 0) errexit("WSAStartup failed\n"); listenfd = socket(AF_INET, SOCK_STREAM, 0); if (listenfd == INVALID_SOCKET) errexit("cannot create socket: error number %d\n", WSAGetLastError()); memset(&servaddr, 0, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port = htons(S_PORT); if (bind(listenfd, (SA *) &servaddr, sizeof(servaddr)) == SOCKET_ERROR) errexit("can't bind to port %d: error number %d\n", S_PORT, WSAGetLastError()); if (listen(listenfd, 5) == SOCKET_ERROR) errexit("can't listen on port %d: error number %d\n", S_PORT, WSAGetLastError()); alen = sizeof(SA); connfd = accept(listenfd, (SA *) &cliaddr, &alen); if (connfd == INVALID_SOCKET) errexit("accept failed: error number %d\n", WSAGetLastError()); printf("accept one client from %s!\n", inet_ntoa(cliaddr.sin_addr)); fp = fopen ("client.c", "rb"); // open file stored in server if (fp == NULL) { printf("\nfile NOT exist"); } //Sending file while(!feof(fp)){ numbytes = fread(buf, sizeof(char), sizeof(buf), fp); printf("fread %d bytes, ", numbytes); numbytes = write(connfd, buf, numbytes); printf("Sending %d bytes\n",numbytes); } fclose (fp); closesocket(listenfd); closesocket(connfd); return 0; }

    Read the article

< Previous Page | 3 4 5 6 7 8 9 10 11 12 13 14  | Next Page >