[PHP] Upload script not working

2004-08-23 Thread Lizet Peña de Sola

Hi all:

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);

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Upload script not working

2004-08-23 Thread John Holmes
From: Lizet Peña de Sola [EMAIL PROTECTED]
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... 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Upload script not working

2004-08-23 Thread Lizet Peña de Sola
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:[EMAIL PROTECTED] 
Sent: Monday, August 23, 2004 3:02 PM
To: Lizet Peña de Sola; [EMAIL PROTECTED]
Subject: Re: [PHP] Upload script not working


From: Lizet Peña de Sola [EMAIL PROTECTED]
 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... 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Upload script not working

2004-08-23 Thread Lizet Peña de Sola

Hello again, tried to remove the last part and the script worked, it looks
like strip_tags strips more than tags...
Thanks a lot
Lizet

-Original Message-
From: John Holmes [mailto:[EMAIL PROTECTED] 
Sent: Monday, August 23, 2004 3:02 PM
To: Lizet Peña de Sola; [EMAIL PROTECTED]
Subject: Re: [PHP] Upload script not working


From: Lizet Peña de Sola [EMAIL PROTECTED]
 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... 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Upload script not working

2004-08-23 Thread John Holmes
From: Lizet Peña de Sola [EMAIL PROTECTED]

Hello Jones, thanks for looking at the code,
will try the uploading without
stripping the tags, I've tried with pdf files
without success.
strip_tags on a PDF file is a bad idea. strip_tags() is only meant for text 
files that may contain HTML tags that you want to remove...

---John Holmes... 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Upload script not working

2004-08-23 Thread Lizet Peña de Sola
Thanks, I better check the file type first then...


strip_tags on a PDF file is a bad idea. strip_tags() is only meant for text 
files that may contain HTML tags that you want to remove...

---John Holmes... 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php