www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] readfile isn't worky properly on Wamp server

  1. #1
    Join Date
    May 2010
    Posts
    42

    resolved [RESOLVED] readfile isn't worky properly on Wamp server

    I pretty much just copied and pasted this from PHP.net's readfile page.
    PHP Code:
    <?php
    $file 
    "C:/wamp/www/Last Night.avi";
    $info pathinfo($file);
    if (
    file_exists($file)) {
        
    header('Content-Description: File Transfer');
        
    header('Content-Type: video/avi');
        
    header('Content-Disposition: attachment; filename='.basename($file$info["extension"]));
        
    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) or die("File not found");
    }
    ?>
    When I run this script, the download dialog pops up but it only downloads about 1kb of the movie. In IE downloads it as "Last Night", no extension, and Firefox downloads it simply as "Last" with no extension. Chrome gets the filename and extension fine.

    Don't know if it has anything to do with it but when I turn off "display errors" Chrome gives me "This webpage is not available".

    Any help would be greatly appreciated. Thanks!

  2. #2
    Join Date
    Feb 2011
    Posts
    231
    Hy,
    Ry use the relative path to the script:
    $file = 'Last Night.avi';
    - also, better names without spaces, e.g "Last_Night.avi"

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,611
    Remove the second parameter to basename(), as that is stripping off the file name suffix. Also, you may want to urlencode() the file name if it could contain spaces or other potentially problematic characters.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  4. #4
    Join Date
    May 2010
    Posts
    42
    Thanks for the replies. No luck, though. I tried taking all the spaces and any special characters out of the file name, I tried a relative link, I also tried another file, an mp4 and got the same results.

    I'm starting to think this may be a problem with my apache configuration. It is finding the file, if I use the wrong path the dialog just won't pop up.

  5. #5
    Join Date
    May 2010
    Posts
    42
    I got it! I opened one of the (what I thought were) incomplete files in textpad and this is what was in there:
    HTML Code:
    <br />
    
    <font size='1'>
    	<table class='xdebug-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
    
    		<tr>
    			<th align='left' bgcolor='#f57900' colspan="5">
    				<span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 209899521 bytes) in C:\wamp\www\downloadLink.php on line <i>17</i>
    			</th>
    		</tr>
    
    		<tr>
    			<th align='left' bgcolor='#e9b96e' colspan='5'>
    				Call Stack
    			</th>
    		</tr>
    		
    <tr>
    			<th align='center' bgcolor='#eeeeec'>
    				#
    			</th>
    			<th align='left' bgcolor='#eeeeec'>
    				Time
    			</th>
    			<th align='left' bgcolor='#eeeeec'>
    				Memory
    			</th>
    			<th align='left' bgcolor='#eeeeec'>
    				Function
    			</th>
    			<th align='left' bgcolor='#eeeeec'>
    				Location
    			</th>
    		</tr>
    		
    <tr>
    			<td bgcolor='#eeeeec' align='center'>
    				1
    			</td>
    			<td bgcolor='#eeeeec' align='center'>
    				0.0005
    			</td>
    			<td bgcolor='#eeeeec' align='right'>
    				673704
    			</td>
    			<td bgcolor='#eeeeec'>
    				{main}(  )
    			</td>
    			<td title='C:\wamp\www\downloadLink.php' bgcolor='#eeeeec'>
    				..\downloadLink.php<b>:</b>0
    			</td>
    		</tr>
    		
    <tr>
    			<td bgcolor='#eeeeec' align='center'>
    				2
    			</td>
    			<td bgcolor='#eeeeec' align='center'>
    				0.0006
    			</td>
    			<td bgcolor='#eeeeec' align='right'>
    				675360
    			</td>
    			<td bgcolor='#eeeeec'>
    				<a href='http://www.php.net/readfile' target='_new'>readfile</a>
    (  )
    			</td>
    			<td title='C:\wamp\www\downloadLink.php' bgcolor='#eeeeec'>
    				..\downloadLink.php<b>:</b>17
    			</td>
    		</tr>
    
    	</table>
    </font>
    What I was actually downloading was a PHP error.
    So it looks like I just need to figure out how to allocate more memory for downloads.

    Edit: If you run into this problem, here's a simple line to put at the beginning of your script:
    PHP Code:
    ini_set("memory_limit","12M"); 
    The 12M is megabytes. So since the video I was downloading was 200 mb, I set it to 300M and it worked perfect.
    Last edited by empireapathy; 05-07-2011 at 06:50 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles