Please help:Cannot view uploaded file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sjagan
Forum Newbie
Posts: 1
Joined: Sat Jun 24, 2006 8:11 pm

Please help:Cannot view uploaded file

Post by sjagan »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I really appreciate & thank you very much for reading my question,here it comes.

Iam new to php & working with xampp on windows since i don have a linux system at the moment & have to get this assignment done asap.I have a problem viewing the uploaded files in (html/htm & ppt ) format 

Iam trying to upload files to a folder i created in Document root.Iam able to upload all the files into the folder,but cannot view them all.

Note: I used a software convertor to convert the excel file to htm format & then uploaded it.

#for the htm file i uploaded its stored as a firefox file into the uploaded folder. When i open the this file from the uploads folder i get a error "This page uses 

frames, but your browser doesn't support them"

I also tried to open the file with IE ,same result.

Is there a way to preserve the format as it was originally.

Now for the PPt File
=========================
# When i open the ppt file i uploaded it says "Powerpoint cannot open the type of file represented by c:\xampp\htdocs\uploads\test.ppt"

# After i upload an image i get " no preview available" when i try to open the image i uploaded.


*****but , i was able to upload & view a text file successfully from the uploads 

folder **********

===================================================

HTML CODE I USED TO BROWSE FILES & send it to storefile.php


[syntax="html"]html>

<body>
<h1>Upload filest</h1>
<form enctype="multipart/form-data" action="storefile.php" method="post">
  <input type="hidden" name="MAX_FILE_SIZE" value="1000000">
  Upload this file: <input name="userfile" type="file">
  <input type="submit" value="Send File">

</form>
</body>
</html>

=======================================================


Here is the action code "storefile.php' i use to store the file in uploads folder

in document root[/syntax]

Code: Select all

<html>
<head>
  <title>Uploading File</title>
</head>

<body>

<?php


  // $userfile is where file went on webserver
  $userfile = $HTTP_POST_FILES['userfile']['tmp_name'];

  // $userfile_name is original file names
  $userfile_name = $HTTP_POST_FILES['userfile']['name'];

  // $userfile_size is size in bytes
  $userfile_size = $HTTP_POST_FILES['userfile']['size'];

  // $userfile_type is mime type e.g. image/gif
  $userfile_type = $HTTP_POST_FILES['userfile']['type'];

  // $userfile_error is any error encountered
  $userfile_error = $HTTP_POST_FILES['userfile']['error'];


// one more check: does the file have the right MIME type?

$userfile_type = 'ppt/html';


// put the file where we'd like it
  $upfile = 'c:/xampp/htdocs/uploads/'.$userfile_name;

// is_uploaded_file and move_uploaded_file added at version 4.0.3
  if (is_uploaded_file($userfile))
  {
     if (!move_uploaded_file($userfile, $upfile))
     {
        echo 'Problem: Could not move file to destination directory';
        exit;
     }
  }
  else
  {
    echo 'Problem: Possible file upload attack. Filename: '.$userfile_name;
    exit;
  }

  echo 'File uploaded successfully!!<br /><br />';

// reformat the file contents
  $fp = fopen($upfile, 'r');
  $contents = fread ($fp, filesize ($upfile));
  fclose ($fp);

  $contents = strip_tags($contents);
  $fp = fopen($upfile, 'w');
  fwrite($fp, $contents);
  fclose($fp);

?>
</body>

</html>


#### could u plese tell me ,where iam going wrong.

$If u can answer my question realtive system that is fine .

Thank u again for taking the time to read my question.


Jay


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

Dude
what's this

Code: Select all

// reformat the file contents
  $fp = fopen($upfile, 'r');
  $contents = fread ($fp, filesize ($upfile));
  fclose ($fp);

  $contents = strip_tags($contents);
  $fp = fopen($upfile, 'w');
  fwrite($fp, $contents);
  fclose($fp);
i think that is your problem... u trying to strip tags from a ppt and jpeg file? crazy man

secondly even if u do u need to use rb or wb where 'b' is a binary safe paramter for reading writing on windows
Post Reply