|
-
July 6th, 2005, 01:24 AM
#1
Write uploaded file directly into a file opened by fopen [PHP 4]
Hi. I have a problem where I have to be able to write an uploaded file directly into a file opened by fopen (Or more specifically, tmpfile). The only way I have found for saving an uploaded file, is move_uploaded_file, but that won't let you write through a file handle.
Is there some other way of making this happen?
Insert entertaining phrase here
-
July 6th, 2005, 03:03 AM
#2
Re: Write uploaded file directly into a file opened by fopen [PHP 4]
I have to be able to write an uploaded file directly into a file opened by fopen
I didn't get what you want to do in particular.
http://de3.php.net/manual/en/functio...oaded-file.php
have you checked out the comment of andrew@euperia,com?
or try to use copy
http://de3.php.net/manual/en/function.copy.php
-
July 6th, 2005, 03:21 AM
#3
Re: Write uploaded file directly into a file opened by fopen [PHP 4]
Sorry about that. Early start this morning. 
I want to write an uploaded file directly into a file created through the tmpfile() function. This function only returns a file-handle, and you can't use move_uploaded_file to write into a file-handle (It only takes a filename parameter).
Is there any other way of accomplishing this, or do I have to resort to my 1337 h4x0ring skillz?
Insert entertaining phrase here
-
July 6th, 2005, 05:09 AM
#4
Re: Write uploaded file directly into a file opened by fopen [PHP 4]
If the uploaded files are textfiles you can use something like this
PHP Code:
<?
$file_stream=$_FILES['userfile']['tmp_name'];
$fp = tmpfile();
fwrite($fp,file_get_contents($file_stream));
rewind($fp);
echo fread($fp, 1024);
?>
Is there a special reason why you want to save the uploaded file
in a tmpfile() ?
-
July 6th, 2005, 05:14 AM
#5
Re: Write uploaded file directly into a file opened by fopen [PHP 4]
Yep, there is actually. The files being uploaded are zip files, and I simply want the contents of them, I don't need the zip itself. Therefore I need to temporarily store the ZIP until I have extracted it. Would that work with the code you posted?
One idea I just though of was to simply call fopen on $_FILES['userfile']['tmp_name'] directly. Would that work, or is there something preventing access to that file?
Insert entertaining phrase here
-
July 6th, 2005, 07:57 AM
#6
Re: Write uploaded file directly into a file opened by fopen [PHP 4]
for unzipping I'm using this free lib
http://www.phpconcept.net/pclzip/index.en.php
$file_stream is the file selected by the user.
e.g.
PHP Code:
<?
require_once('pclzip.lib.php');
$file_stream=$_FILES['userfile']['tmp_name'];
$archive = new PclZip($file_stream);
if ($archive->extract() == 0) {
die("Error : ".$archive->errorInfo(true));
}
?>
-
July 7th, 2005, 12:32 AM
#7
Re: Write uploaded file directly into a file opened by fopen [PHP 4]
Thanks, I'll take a look at it.
Insert entertaining phrase here
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|