0

Hi,

How can I read a file content without uploading it to the server? I know that we use $handler = fopen('regular.csv', 'r'); to read an existing file on server but what if doesn't exist.

Obviously $_FILES is used to move file to server first but I don't have any folder writable and won't be given one. That's why I need to do this way.

Thanks

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by veledrom
0

Try this to see if you can save to php temporary folder. I'm surprised your host doesn't allow file upload. Is it a free service?

<?php
if(isset($_FILES["file"])){
    if ($_FILES["file"]["error"] > 0){
        echo "Error: " . $_FILES["file"]["error"] . "<br />";
    }else{
        $var = file_get_contents($_FILES["file"]["tmp_name"]);
        echo $var;  //test
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>...</title>
</head>
<body>
<form enctype="multipart/form-data" method="post">
<input name="file" type="file" />
<input name="sub" type="submit" value="go" />
</form>    
</body>
</html>

The temporary file (the one used in the form), will de deleted at the end of the script run. Works for me, but there again, I don't have such restrictions.

0

What kind of environment is your server running? If the host is using the suPHP module instead of the standard apache DSO module then your scripts execute as your user. So any files/directories may be writable, without having to be 777 etc.

0

Nice one diafol.

I've never though of reading $_FILES["file"]["tmp_name"] to be honest.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.