RE: [PHP] Upload script not working
| From: | Lizet Peña de Sola | Date: | Mon, 23 Aug 2004 18:49:12 +0000 |
| Subject: | RE: [PHP] Upload script not working | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-194512@lists.php.net to get a copy of this message | ||
Hello Jones, thanks for looking at the code, will try the uploading without
stripping the tags, I've tried with pdf files without success.
Lizet
-----Original Message-----
From: John Holmes [mailto:holmes072000@charter.net]
Sent: Monday, August 23, 2004 3:02 PM
To: Lizet Peña de Sola; php-general@lists.php.net
Subject: Re: [PHP] Upload script not working
From: "Lizet Peña de Sola" <lizet@krosslink.com>
> I have the following script to upload files to the server, it works
> partially as only a few bytes of the file are uploaded, is the script
> wrong or am I missing some setting at the server?
> Tia,
> Lizet
>
> userfile=$_FILES['userfile']['tmp_name'];
> // $userfile_name is the original file name without spaces
> $userfile_name=str_replace("
> ","_",$_FILES['userfile']['name']);
> // $userfile_size the size in bytes
> $userfile_size=$_FILES['userfile']['size'];
> //$userfile_type is mime type e.g. image/gif
> $userfile_type=$_FILES['userfile']['type'];
> // $userfile_error is any error encountered
> $userfile_error=$_FILES['userfile']['error'];
> if($userfile_error > 0){
> $str="Problem: ";
> switch ($userfile_error){
> case 1: $str=$str."error 1"; break;
> case 2: $str=$str."error2"; break;
> case 3: $str=$str."erro3"; break;
> case 4: $str=$str."error4"; break;
> }
> exit;
> }
> $upfile= 'files/'.$userfile_name; $temp1=is_uploaded_file($userfile);
> if($temp1){
> $temp2=move_uploaded_file($userfile,$upfile);
> if(!$temp2){
> $str="Problem: The file could not be moved.";
> //exit;
> }
>
> }
> else{
> $str="Problem: file corrupted: ".$userfile_name;
> }
> //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 don't notice anything wrong with the script after glancing through it. If
you take out the end portion where you strip the tags from the file, so you
still end
up with a smaller file as a result? Maybe strip_tags() is removing more
content than you think it is? Either way, you're going to end up with a
smaller file.
---John Holmes...