Search Results

Search found 197 results on 8 pages for 'readfile'.

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

  • PHP readfile for force downloading files and images

    - by jiexi
    I want to send files through php using readfile() What i've noticed is that readfile forces a download, but what if i want to show an image in the browser and not force a download? Would readfile still force download even if the file is an image? If it does, is there a solution so i can use tags with it when the file is an image? Thanks!

    Read the article

  • @readfile in php??

    - by Jonathan
    I hate that google can not search for symbols. I saw this in some sample code and wondered why there is an @ sign before the readfile function: @readfile($filename); What does it mean different to without an @ symbol?

    Read the article

  • According to MSDN ReadFile() Win32 function may incorrectly report read operation completion. When?

    - by Martin Dobšík
    The MSDN states in its description of ReadFile() function (http://msdn.microsoft.com/en-us/library/aa365467%28VS.85%29.aspx): “If hFile is opened with FILE_FLAG_OVERLAPPED, the lpOverlapped parameter must point to a valid and unique OVERLAPPED structure, otherwise the function can incorrectly report that the read operation is complete.” I have some applications that are violating the above recommendation and I would like to know the severity of the problem. I mean the program uses named pipe that has been created with FILE_FLAG_OVERLAPPED, but it reads from it using the following call: ReadFile(handle, &buf, n, &n_read, NULL); That means it passes NULL as the lpOverlapped parameter. That call should not work correctly in some circumstances according to documentation. I have spent a lot of time trying to reproduce the problem, but I was unable to! I always got all data in right place at right time. I was testing only Named Pipes though. Would anybody know when can I expect that ReadFile() will incorrectly return and report successful completion even the data are not yet in the buffer? What would have to happen in order to reproduce the problem? Does it happen with files, pipes, sockets, consoles, or other devices? Do I have to use particular version of OS? Or particular version of reading (like register the handle to I/O completion port)? Or particular synchronization of reading and writing processes/threads? Or when would that fail? It works for me :/ Please help! With regards Martin

    Read the article

  • ReadFile doesn't work asynchronously on Win7 and Win2k8

    - by f0b0s
    According to MSDN ReadFile can read data 2 different ways: synchronously and asynchronously. I need the second one. The folowing code demonstrates usage with OVERLAPPED struct: #include <windows.h> #include <stdio.h> #include <time.h> void Read() { HANDLE hFile = CreateFileA("c:\\1.avi", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if ( hFile == INVALID_HANDLE_VALUE ) { printf("Failed to open the file\n"); return; } int dataSize = 256 * 1024 * 1024; char* data = (char*)malloc(dataSize); memset(data, 0xFF, dataSize); OVERLAPPED overlapped; memset(&overlapped, 0, sizeof(overlapped)); printf("reading: %d\n", time(NULL)); BOOL result = ReadFile(hFile, data, dataSize, NULL, &overlapped); printf("sent: %d\n", time(NULL)); DWORD bytesRead; result = GetOverlappedResult(hFile, &overlapped, &bytesRead, TRUE); // wait until completion - returns immediately printf("done: %d\n", time(NULL)); CloseHandle(hFile); } int main() { Read(); } On Windows XP output is: reading: 1296651896 sent: 1296651896 done: 1296651899 It means that ReadFile didn't block and returned imediatly at the same second, whereas reading process continued for 3 seconds. It is normal async reading. But on windows 7 and windows 2008 I get following results: reading: 1296661205 sent: 1296661209 done: 1296661209. It is a behavior of sync reading. MSDN says that async ReadFile sometimes can behave as sync (when the file is compressed or encrypted for example). But the return value in this situation should be TRUE and GetLastError() == NO_ERROR. On Windows 7 I get FALSE and GetLastError() == ERROR_IO_PENDING. So WinApi tells me that it is an async call, but when I look at the test I see that it is not! I'm not the only one who found this "bug": read the comment on ReadFile MSDN page. So what's the solution? Does anybody know? It is been 14 months after Denis found this strange behavior.

    Read the article

  • Using readfile() with remote URL and SSL

    - by ColmF
    I have a php-based website that uses SSL and requires a a user to login before accessing any page. I would like to allow access to this site from another domain, so that the functionality remains the same, but the look, feel and domain changes for the user (with the added advantage that I have to maintain only one version of the code). Having done some reading, I'm using readfile() function calls in php files on the secondary server to corresponding files on the primary server. For example, the login.php on the primary server is accessed from the secondary server by a file called login.php containing readfile("http://www.primarydomain.com/login.php") (and nothing else). Now the problem - I can't even login! The login page appears fine when called initially, but when login user and pwd are entered and submitted, it's as if the remote server doesn't see the $_SERVER['REQUEST_METHOD'] variable that triggers form processing and just loads as an empty form. Any ideas what I'm doing wrong or what configuation I might need to change? Thanks!

    Read the article

  • PHP readfile() and large downloads

    - by Nirmal
    While setting up an online file management system, and now I have hit a block. I am trying to push the file to the client using this modified version of readfile: function readfile_chunked($filename,$retbytes=true) { $chunksize = 1*(1024*1024); // how many bytes per chunk $buffer = ''; $cnt =0; // $handle = fopen($filename, 'rb'); $handle = fopen($filename, 'rb'); if ($handle === false) { return false; } while (!feof($handle)) { $buffer = fread($handle, $chunksize); echo $buffer; ob_flush(); flush(); if ($retbytes) { $cnt += strlen($buffer); } } $status = fclose($handle); if ($retbytes && $status) { return $cnt; // return num. bytes delivered like readfile() does. } return $status; } But when I try to download a 13 MB file, it's just breaking at 4 MB. What would be the issue here? It's definitely not the time limit of any kind because I am working on a local network and speed is not an issue. The memory limit in PHP is set to 300 MB. Thank you for any help.

    Read the article

  • Getting Junk characters while trying to print the file contents using Java

    - by user1523797
    I am reading a file's contents and trying to print the contents using java. But it prints junk characters along with the file content. Code: import java.io.*; public class ReadFile { public String readFile(String filePath){ StringBuilder contents = new StringBuilder(); File file = new File(filePath); try{ String lines = null; FileReader fileReader1 = new FileReader(file); BufferedReader buffer = new BufferedReader(fileReader1); while((lines = buffer.readLine())!=null){ contents.append(lines); } buffer.close(); } catch(FileNotFoundException ex){ System.out.println("File not found."); }catch(IOException ex){ System.out.println("Exception ocurred."); } return contents.toString(); } public static void main(String[] args){ ReadFile rf = new ReadFile(); String lines = rf.readFile("C:\\Data\\FaultDn.txt"); System.out.println("Original file contents: " + lines); } } The file contents are: partner.cisco.com:org-root/mac-pool-QA_MAC_Pool_5-Sep-2012_12:00 The output is: ![Alt Output](C:\Users\safarhee\Desktop\Output.jpg) Can you please point me to what I am missing in this code?

    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

  • How to let users with required permission download a file via php?

    - by Yegor
    I have a php file that acts as a gatekeeper for all the files I want people to download, who ahve sufficient privilages. The code I use throw the file to the user is header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header("Content-disposition: attachment; filename=\"".$public_filename."\""); 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: ".$f_filesize); readfile($file_path); Most files are fairly large.... 400mb-10GB. What would be a good way to do this, and keep the true locations + filenames secret, so people cant just link to the files directly, but HAVE to link thru my download.php?file=ID gatekeeper? Thanks

    Read the article

  • how can i redirect page while download box appears?

    - by Ronnie Chester Lynwood
    Now I got this code; <?php $file = "pain.png"; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($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); exit; } ?> This code appears a download box. But I want to redirect this page to "Thank You" page while download box still here. How can i do this? Thanks...

    Read the article

  • PHP: How to know if a user is currently downloading a file?

    - by metrobalderas
    I'm developing a quick rapidshare-like site where the user can download files. First, I created a quick test setting headers and using readfile() but then I found in the comments section there's a way to limit the speed of the download, which is great, here's the code: $local_file = 'file.zip'; $download_file = 'name.zip'; // set the download rate limit (=> 20,5 kb/s) $download_rate = 20.5; if(file_exists($local_file) && is_file($local_file)) { header('Cache-control: private'); header('Content-Type: application/octet-stream'); header('Content-Length: '.filesize($local_file)); header('Content-Disposition: filename='.$download_file); flush(); $file = fopen($local_file, "r"); while(!feof($file)) { // send the current file part to the browser print fread($file, round($download_rate * 1024)); // flush the content to the browser flush(); // sleep one second sleep(1); } fclose($file);} else { die('Error: The file '.$local_file.' does not exist!'); } But now my question is, how to limit the number of downloads at the same time? How can I check there's still a connection with some user's IP? Thanks.

    Read the article

  • How to obtain the first cluster of the directory's data in FAT using C# (or at least C++) and Win32A

    - by DarkWalker
    So I have a FAT drive, lets say H: and a directory 'work' (full path 'H:\work'). I need to get the NUMBER of the first cluster of that directory. The number of the first cluster is 2-bytes value, that is stored in the 26th and 27th bytes of the folder enty (wich is 32 bytes). Lets say I am doing it with file, NOT a directory. I can use code like this: static public string GetDirectoryPtr(string dir) { IntPtr ptr = CreateFile(@"H:\Work\dover.docx", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, IntPtr.Zero, OPEN_EXISTING, 0,//FILE_FLAG_BACKUP_SEMANTICS, IntPtr.Zero); try { const uint bytesToRead = 2; byte[] readbuffer = new byte[bytesToRead]; if (ptr.ToInt32() == -1) return String.Format("Error: cannot open direcotory {0}", dir); if (SetFilePointer(ptr, 26, 0, 0) == -1) return String.Format("Error: unable to set file pointer on file {0}", ptr); uint read = 0; // real count of read bytes if (!ReadFile(ptr, readbuffer, bytesToRead, out read, 0)) return String.Format("cant read from file {0}. Error #{1}", ptr, Marshal.GetLastWin32Error()); int result = readbuffer[0] + 16 * 16 * readbuffer[1]; return result.ToString();//ASCIIEncoding.ASCII.GetString(readbuffer); } finally { CloseHandle(ptr); } } And it will return some number, like 19 (quite real to me, this is the only file on the disk). But I DONT need a file, I need a folder. So I am puttin FILE_FLAG_BACKUP_SEMANTICS param for CreateFile call... and dont know what to do next =) msdn is very clear on this issue http://msdn.microsoft.com/en-us/library/aa365258(v=VS.85).aspx It sounds to me like: "There is no way you can get a number of the folder's first cluster". The most desperate thing is that my tutor said smth like "You are going to obtain this or you wont pass this course". The true reason why he is so sure this is possible is because for 10 years (or may be more) he recieved the folder's first cluster number as a HASH of the folder's addres (and I was stupid enough to point this to him, so now I cant do it the same way) PS: This is the most spupid task I have ever had!!! This value is not really used anythere in program, it is only fcking pointless integer.

    Read the article

  • Where to put a textfile I want to use in eclipse?

    - by Jayomat
    hi there, I need to read a text file when I start my program. I'm using eclipse and started a new java project. In my project folder I got the "src" folder and the standard "JRE System Library"... I just don't know where to put the text file. I cannot use a "hard coded" path because the text file needs to be included with my app... I also tried to create a new folder like "Files" and use the pathe "Files/staedteliste.txt".. doesn't work too... I use the following code to read the file, but I get this error: Error:java.io.FileNotFoundException:staedteliste.txt(No such file or directory) import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; public class Test { ArrayList<String[]> values; public static void main(String[] args) { // TODO Auto-generated method stub loadList(); } public static void loadList() { BufferedReader reader; String zeile = null; try { reader = new BufferedReader(new FileReader("staedteliste.txt")); zeile = reader.readLine(); ArrayList<String[]> values = new ArrayList<String[]>(); while (zeile != null) { values.add(zeile.split(";")); zeile = reader.readLine(); } System.out.println(values.size()); System.out.println(zeile); } catch (IOException e) { System.err.println("Error :"+e); } } } thx for help!

    Read the article

  • how to read specific number of floats from file in python?

    - by sahel
    I am reading a text file from the web. The file starts with some header lines containing the number of data points, followed the actual vertices (3 coordinates each). The file looks like: # comment HEADER TEXT POINTS 6 float 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 POLYGONS the line starting with the word POINTS contains the number of vertices (in this case we have 3 vertices per line, but that could change) This is how I am reading it right now: ur=urlopen("http://.../file.dat") j=0 contents = [] while 1: line = ur.readline() if not line: break else: line=line.lower() if 'points' in line : myline=line.strip() word=myline.split() node_number=int(word[1]) node_type=word[2] while 'polygons' not in line : line = ur.readline() line=line.lower() myline=line.split() i=0 while(i<len(myline)): contents[j]=float(myline[i]) i=i+1 j=j+1 How can I read a specified number of floats instead of reading line by line as strings and converting to floating numbers? Instead of ur.readline() I want to read the specified number of elements in the file Any suggestion is welcome..

    Read the article

  • Read data from a text file using Java

    - by Saran
    I need to read a text file line by line using Java. I use available() method of FileInputStream to check and loop over the file. But while reading, the loop terminates after the line before the last one. i.e., if the file has 10lines, the loop reads only the first 9 lines. Snippet used : while(fis.available() > 0) { char c = (char)fis.read(); ..... ..... }

    Read the article

  • Output reformatted text within a file included in a JSP

    - by javanix
    I have a few HTML files that I'd like to include via tags in my webapp. Within some of the files, I have pseudo-dynamic code - specially formatted bits of text that, at runtime, I'd like to be resolved to their respective bits of data in a MySQL table. For instance, the HTML file might include a line that says: Welcome, [username]. I want this resolved to (via a logged-in user's data): Welcome, [email protected]. This would be simple to do in a JSP file, but requirements dictate that the files will be created by people who know basic HTML, but not JSP. Simple text-tags like this should be easy enough for me to explain to them, however. I have the code set up to do resolutions like that for strings, but can anyone think of a way to do it across files? I don't actually need to modify the file on disk - just load the content, modify it, and output it w/in the containing JSP file. I've been playing around with trying to load the files into strings via the apache readFileToString, but I can't figure out how to load files from a specific folder within the webapp's content directory without hardcoding it in and having to worry about it breaking if I deploy to a different system in the future.

    Read the article

  • How to read line by line a CR-only file with Perl?

    - by Subb
    Hi, I'm trying to read a file which has only CR as line delimiter. I'm using Mac OS X and Perl v.5.8.8. This script should run on every platform, for every kind of line delimiter (CR, LF, CRLF). My current code is the following : open(FILE, "test.txt"); while($record = <FILE>){ print $record; } close(TEST); This currently print only the last line (or worst). What is going on? Obvisously, I would like to not convert the file. Is it possible?

    Read the article

  • how to pass an array into an function and in the function count how many numbers are in a range?

    - by user320950
    #include <iostream> #include <fstream> using namespace std; int calculate_total(int exam1[], int exam2[], int exam3[]); // function that calcualates grades to see how many 90,80,70,60 int exam1[100];// array that can hold 100 numbers for 1st column int exam2[100];// array that can hold 100 numbers for 2nd column int exam3[100];// array that can hold 100 numbers for 3rd column // here i am passing an array into the function calcualate_total int calculate_total(exam1[],exam2[],exam3[]) { int above90=0, above80=0, above70=0, above60=0; if((num<=90) && (num >=100)) { above90++; { if((num<=80) && (num >=89)) { above80++; { if((num<=70) && (num >=79)) { above70++; { if((num<=60) && (num >=69)) { above60++; } } } } } } } }

    Read the article

  • Editing a remote file on-the-fly with PHP

    - by user275074
    Hi, I have a requirement to edit a remote text file on-the-fly, the content of which currently stands at ~1Mb. I have tried a couple of approaches and both seem to be clunky or hog memory which I can't rely on. Thinking out logically what I'm trying to achieve is: FTP to a remote server. Download a copy of the file for backup purposes and store it somewhere locally. Open the remote file and add the necessary lines required. Remove lines from the remote file as per an array of un-required data generated from the local server. Is this possible? I've managed to code steps 1 and 2 but I'm having difficult with 3 and 4. The way I'm doing it now is to use fgets and return the whole string. Really, I don't want to do this as it involves manipulating and re-generating the whole string (and it's large) and then re-inserting it in between two markers in the remote file. Is there no way of manipulating the lines of text in the file on-the-fly?

    Read the article

  • Delete System Files containing string

    - by Fuzz Evans
    I am trying to write a batch file that will examine a given directory, read each file for a given string "Example" and then delete any files that contain the string. The files are also System Files so I don't know what the exact extension is or if that matters (maybe you can just omit a file type filter and have it read all files?). Some of the files will be locked from reading as well so it needs to handle access denial errors if that occurs, not sure how batch files handle that.

    Read the article

  • NullReferenceExeption when reading from a file

    - by Whitey
    I need to read a file structured like this: 01000 00030 00500 03000 00020 And put it in an array like this: int[,] iMap = new int[iMapHeight, iMapWidth] { {0, 1, 0, 0, 0}, {0, 0, 0, 3, 0}, {0, 0, 5, 0, 0}, {0, 3, 0, 0, 0}, {0, 0, 0, 2, 0}, }; Hopefully you see what I'm trying to do here. I was confused how to do this so I asked here on SO, but the code I got from it gets this error: Object reference not set to an instance of an object. I'm pretty new to this so I have no idea how to fix it... I only barely know the code: protected void ReadMap(string mapPath) { using (var reader = new StreamReader(mapPath)) { for (int i = 0; i < iMapHeight; i++) { string line = reader.ReadLine(); for (int j = 0; j < iMapWidth; j++) { iMap[i, j] = (int)(line[j] - '0'); } } } } The line I get the error on is this: iMap[i, j] = (int)(line[j] - '0'); Can anyone provide a solution? Thank you. :)

    Read the article

  • reading a random access file

    - by user1067332
    The file I create has text in it, but when i try to read it, the output is null. here is the file the creates the text file, it creates the file and puts it in the right postion import java.util.*; import java.io.*; public class CreateCustomerFile { public static void main(String[] args) throws IOException { int pos; RandomAccessFile it = new RandomAccessFile("CustomerFile.txt", "rw"); Scanner input = new Scanner(System.in); int id; String name; int zip; final int RECORDSIZE = 100; final int NUMRECORDS = 1000; final int STOP = 99; try { for(int x = 0; x < NUMRECORDS; ++x) { it.writeInt(0); it.writeUTF(""); it.writeInt(0); } } catch(IOException e) { System.out.println("Error: " + e.getMessage()); } finally { it.close(); } it = new RandomAccessFile("CustomerFile.txt","rw"); try { System.out.print("Enter ID number" + " or " + STOP + " to quit "); id = input.nextInt(); while(id != STOP) { input.nextLine(); System.out.print("Enter last name"); name = input.nextLine(); System.out.print("Enter zipcode "); zip = input.nextInt(); pos = id - 1; it.seek(pos * RECORDSIZE); it.writeInt(id); it.writeUTF(name); it.writeInt(zip); System.out.print("Enter ID number" + " or " + STOP + " to quit "); id = input.nextInt(); } } catch(IOException e) { System.out.println("Error: " + e.getMessage()); } finally { it.close(); } } } Here is the file to read, the pos is correct but ouput always goes to the error: null. import javax.swing.*; import java.io.*; public class CustomerItemOrder { public static void main(String[] args) throws IOException { int pos; RandomAccessFile it = new RandomAccessFile("CustomerFile.txt","rw"); String inputString; int id, zip; String name; final int RECORDSIZE = 100; final int STOP = 99; inputString = JOptionPane.showInputDialog(null, "Enter id or "+ STOP + " to quit"); id = Integer.parseInt(inputString); try { while(id != STOP) { pos = id -1 ; it.seek(pos * RECORDSIZE ); id = it.readInt(); name = it.readLine(); zip = it.readInt(); JOptionPane.showMessageDialog(null, "ID:" + id + " last name is " + name + " and zipcode is " + zip); inputString = JOptionPane.showInputDialog(null, "Enter id or " + STOP + " to quit"); id = Integer.parseInt(inputString); } } catch(IOException e) { System.out.println("Error: " + e.getMessage()); } finally { it.close(); } } }

    Read the article

  • C#: reading in a text file more 'intelligently'

    - by DarthSheldon
    I have a text file which contains a list of alphabetically organized variables with their variable numbers next to them formatted something like follows: aabcdef 208 abcdefghijk 1191 bcdefga 7 cdefgab 12 defgab 100 efgabcd 999 fgabc 86 gabcdef 9 h 11 ijk 80 ... ... I would like to read each text as a string and keep it's designated id# something like read "aabcdef" and store it into an array at spot 208. The 2 issues I'm running into are: I've never read from file in C#, is there a way to read, say from start of line to whitespace as a string? and then the next string as an int until the end of line? given the nature and size of these files I do not know the highest ID value of each file (not all numbers are used so some files could house a number like 3000, but only actually list 200 variables) So how could I make a flexible way to store these variables when I don't know how big the array/list/stack/etc.. would need to be.

    Read the article

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