Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 754 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

php upload script problem

Thread title: php upload script problem
Closed Thread  
Page 1 of 3 1 2 3 >
    Thread tools Search this thread Display Modes  
08-07-2006, 04:30 PM
#1
Nightscream is offline Nightscream
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
 
Posts: 58
iTrader: 0 / 0%
 

Nightscream is on a distinguished road

  Old  php upload script problem

I'm creating my own upload script but It won't work
if I want to upload something i get
File '' not uploaded
It's something with the $_FILES i think but don't know how to fix it
PHP Code:
if( isset( $_POST['Upload'] )) {
    
$upload_dir $_SERVER['DOCUMENT_ROOT'] . "images/";
    
$MaxFileSize 800000000;
    
$filename $_FILES['file']['name'];
    
$filesize $_FILES['file']['size'];
    
$filetmpname $_FILES['file']['tmp_name'];
    
$allowed_types = array( "jpg""gif""png" );
    
$filetype substr($filename, -33);
    
//$Thumb = $_POST['Thumbnail'];
    //$Water = $_POST['Watermarking'];
    
    
if($filename) {
    echo 
'test';
    
$error 0;
        if((
$filesize $MaxFileSize) | $filesize ) {
            
$error 1;
            
$errmsg .= "Your File is to large, (Max File size: 8MB)";
        }
        if( !
in_array$filetype$allowed_types )) {
            
$error 1;
            
$errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
        }else  {
            
$error 0;
        }
        if( 
$error ) {
            die( 
"$errmsg);
        }else{                
            
$num rand19999 );
            
$new_filename $num.$filename;
            
$upload move_uploaded_file($filetmpname"$upload_dir.$new_filename");
            if(
$Thumb ) {
                
CreateThumb($filetmpname);
            }
            if(
$Water ) {
                
CreateWatermark($filetmpname);
            }
            if( 
$upload ) {
                echo 
'Upload Succesfull';
                
//echo "<meta http-equiv='refresh' content='0'; URL='?image=$upload_dir.$new_filename'>";
            
}else {
                die( 
"Cound not upload the file, please try again" );
            }
        }
    }else{
        echo 
"File '$filename' not uploaded";
    }
}
?> 

08-07-2006, 04:35 PM
#2
Garyrae is offline Garyrae
Status: Request a custom title
Join date: Dec 2005
Location: Colchester, UK
Expertise:
Software:
 
Posts: 4,625
iTrader: 16 / 100%
 

Garyrae is on a distinguished road

Send a message via MSN to Garyrae Send a message via Skype™ to Garyrae

  Old

if( !in_array( $_FILE['File']['type'], $allowed_types )) {

Should be:
if( !in_array( $_FILES['file']['type'], $allowed_types )) {

08-07-2006, 04:46 PM
#3
Nightscream is offline Nightscream
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
 
Posts: 58
iTrader: 0 / 0%
 

Nightscream is on a distinguished road

  Old

nope changed that, still the same error.
and
PHP Code:
if($filename) {
    echo 
'test'
i don't see that eighter

08-07-2006, 06:22 PM
#4
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

Take out the if($filename), it doesn't do anything at all.

08-07-2006, 06:46 PM
#5
sketchie is offline sketchie
sketchie's Avatar
Status: Senior Member
Join date: Jul 2005
Location:
Expertise:
Software:
 
Posts: 835
iTrader: 1 / 100%
 

sketchie is on a distinguished road

  Old

I had a quick glance through, and unless PHP has changed since i last dabbed with it,

PHP Code:
if(($filesize $MaxFileSize) | $filesize ) { 
should be

PHP Code:
if(($filesize $MaxFileSize) || $filesize == ) { 
As in PHP or is || not |, and you're also not checking if the filesize is 0 by using "=" this is the assignment operator, you need ==.

Edit:

You've also done it here:
PHP Code:
if( $error ) { 
make it
PHP Code:
if( $error == ) { 
Though I don't see why you're doing it like this, using integers rather than booleans.

08-07-2006, 07:02 PM
#6
iisbum is offline iisbum
iisbum's Avatar
Status: Member
Join date: Oct 2005
Location: Clifton Park, NY, USA
Expertise:
Software:
 
Posts: 273
iTrader: 4 / 100%
 

iisbum is on a distinguished road

  Old

Other than the script changes mentioned by the other posters, it would also be helpful to see the form that you're using to submit into the script, to confirm the name of form fields and the encoding type on the form, which may be the other reason you're not seeing the file uploaded.

Mubs

08-07-2006, 09:38 PM
#7
Nightscream is offline Nightscream
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
 
Posts: 58
iTrader: 0 / 0%
 

Nightscream is on a distinguished road

  Old

ok that's the problem right now, I can't go on my computer, It got an error that i'm fixing right now but it takes ages.
I'll post it later

08-08-2006, 10:54 AM
#8
Nightscream is offline Nightscream
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
 
Posts: 58
iTrader: 0 / 0%
 

Nightscream is on a distinguished road

  Old

this is my full code
PHP Code:
<?php
define 
('THUMBWIDTH'100);
define ('THUMBHEIGHT'100);
function 
CreateThumb($src) {
    
copy$filetmpname"$upload_dir'.thumb.'$new_filename);
    list(
$width$height$type$attr) = getimagesize($src);
    
$img imagecreatefromstring(file_get_contents($src));
    
$lowest min(THUMBWIDTH $widthTHUMBHEIGHT $height);
    if(
$lowest 1) {
        
$smallwidth floor($lowest*$width);
        
$smallheight floor($lowest*$height);
        
$tmp imagecreatetruecolor($smallwidth$smallheight);
        
imagecopyresized($tmp$img0000$smallwidth$smallheight$width$height);
        
imagedestroy($img);
        
$img $tmp;
    }
}
function 
CreateWatermark($src) {
    
$img imagecreatefromstring(file_get_contents($src));
    
$red imagecolorallocate($img0xFF0x000x00);
    
imagestring($img533WATERMARK$red);
}
if( isset( 
$_POST['Upload'] )) {
    
$upload_dir $_SERVER['DOCUMENT_ROOT'] . "images/";
    
$MaxFileSize 800000000;
    
$filename $_FILES['file']['name'];
    
$filesize $_FILES['file']['size'];
    
$filetmpname $_FILES['file']['tmp_name'];
    
$allowed_types = array( "jpg""gif""png" );
    
$filetype substr($filename, -33);
    
//$Thumb = $_POST['Thumbnail'];
    //$Water = $_POST['Watermarking'];
    
    
if($filename) {
    echo 
'test';
    
$error 0;
        if((
$filesize $MaxFileSize) | $filesize ) {
            
$error 1;
            
$errmsg .= "Your File is to large, (Max File size: 8MB)";
        }
        if( !
in_array$filetype$allowed_types )) {
            
$error 1;
            
$errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
        }else  {
            
$error 0;
        }
        if( 
$error ) {
            die( 
"$errmsg);
        }else{                
            
$num rand19999 );
            
$new_filename $num.$filename;
            
$upload move_uploaded_file($filetmpname"$upload_dir.$new_filename");
            if(
$Thumb ) {
                
CreateThumb($filetmpname);
            }
            if(
$Water ) {
                
CreateWatermark($filetmpname);
            }
            if( 
$upload ) {
                echo 
'Upload Succesfull';
                
//echo "<meta http-equiv='refresh' content='0'; URL='?image=$upload_dir.$new_filename'>";
            
}else {
                die( 
"Cound not upload the file, please try again" );
            }
        }
    }else{
        echo 
"File '$filename' not uploaded";
    }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<center>
<script language='JavaScript' type='text/javascript'>
<!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);

   document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://x10hosting.com/advert/adjs.php?n=" + phpAds_random);
   document.write ("&what=zone:1&target=_blank");
   document.write ("&exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&referer=" + escape(document.referrer));
   document.write ("'><" + "/script>");
//-->

</script><noscript><a href='http://x10hosting.com/advert/adclick.php?n=a7fb3e9d' target='_blank'><img src='http://x10hosting.com/advert/adview.php?what=zone:1&n=a7fb3e9d' border='0' alt=''></a></noscript>
<br />
<form action="uploadform.php" method="post">
<input type="file" name="file"><br />
JPG, GIF, PNG uploadable files.<br />
<input type="checkbox" name="Thumbnail"> Thumbnails option<br />
<input type="checkbox" name="Watermarking"> Watermarking option<br />
<input type="submit" name="Upload" value="Upload File">
</form></center>
</body>
</html>

08-08-2006, 10:58 AM
#9
sketchie is offline sketchie
sketchie's Avatar
Status: Senior Member
Join date: Jul 2005
Location:
Expertise:
Software:
 
Posts: 835
iTrader: 1 / 100%
 

sketchie is on a distinguished road

  Old

Have you made the fixes I mentioned before? They still stand..

08-08-2006, 01:57 PM
#10
Nightscream is offline Nightscream
Status: Junior Member
Join date: Aug 2006
Location:
Expertise:
Software:
 
Posts: 58
iTrader: 0 / 0%
 

Nightscream is on a distinguished road

  Old

updated code here
PHP Code:
<?php
define 
('THUMBWIDTH'100);
define ('THUMBHEIGHT'100);
function 
CreateThumb($src) {
    
copy$filetmpname"$upload_dir'.thumb.'$new_filename);
    list(
$width$height$type$attr) = getimagesize($src);
    
$img imagecreatefromstring(file_get_contents($src));
    
$lowest min(THUMBWIDTH $widthTHUMBHEIGHT $height);
    if(
$lowest 1) {
        
$smallwidth floor($lowest*$width);
        
$smallheight floor($lowest*$height);
        
$tmp imagecreatetruecolor($smallwidth$smallheight);
        
imagecopyresized($tmp$img0000$smallwidth$smallheight$width$height);
        
imagedestroy($img);
        
$img $tmp;
    }
}
function 
CreateWatermark($src) {
    
$img imagecreatefromstring(file_get_contents($src));
    
$red imagecolorallocate($img0xFF0x000x00);
    
imagestring($img533WATERMARK$red);
}
if( isset( 
$_POST['Upload'] )) {
    
$upload_dir $_SERVER['DOCUMENT_ROOT'] . "images/";
    
$MaxFileSize 800000000;
    
$filename $_FILES['file']['name'];
    
$filesize $_FILES['file']['size'];
    
$filetmpname $_FILES['file']['tmp_name'];
    
$allowed_types = array( "jpg""gif""png" );
    
$filetype substr($filename, -33);
    
//$Thumb = $_POST['Thumbnail'];
    //$Water = $_POST['Watermarking'];
    
    
if($filename) {
    echo 
'test';
    
$error 0;
        if((
$filesize $MaxFileSize) || $filesize ) {
            
$error 1;
            
$errmsg .= "Your File is to large, (Max File size: 8MB)";
        }
        if( !
in_array$filetype$allowed_types )) {
            
$error 1;
            
$errmsg .= "Your File is the wrong type, (Allowed Types: Gif, Jpg, Png)//change to the allowed types";
        }else  {
            
$error 0;
        }
        if( 
$error == ) {
            die( 
"$errmsg);
        }else{                
            
$num rand19999 );
            
$new_filename $num.$filename;
            
$upload move_uploaded_file($filetmpname"$upload_dir.$new_filename");
            if(
$Thumb == ) {
                
CreateThumb($filetmpname);
            }
            if(
$Water == ) {
                
CreateWatermark($filetmpname);
            }
            if( 
$upload ) {
                echo 
'Upload Succesfull';
                
//echo "<meta http-equiv='refresh' content='0'; URL='?image=$upload_dir.$new_filename'>";
            
}else {
                die( 
"Cound not upload the file, please try again" );
            }
        }
    }else{
        echo 
"File '$filename' not uploaded";
    }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<center>
<script language='JavaScript' type='text/javascript'>
<!--
   if (!document.phpAds_used) document.phpAds_used = ',';
   phpAds_random = new String (Math.random()); phpAds_random = phpAds_random.substring(2,11);

   document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
   document.write ("http://x10hosting.com/advert/adjs.php?n=" + phpAds_random);
   document.write ("&what=zone:1&target=_blank");
   document.write ("&exclude=" + document.phpAds_used);
   if (document.referrer)
      document.write ("&referer=" + escape(document.referrer));
   document.write ("'><" + "/script>");
//-->

</script><noscript><a href='http://x10hosting.com/advert/adclick.php?n=a7fb3e9d' target='_blank'><img src='http://x10hosting.com/advert/adview.php?what=zone:1&n=a7fb3e9d' border='0' alt=''></a></noscript>
<br />
<form action="uploadform.php" method="post">
<input type="file" name="file"><br />
JPG, GIF, PNG uploadable files.<br />
<input type="checkbox" name="Thumbnail"> Thumbnails option<br />
<input type="checkbox" name="Watermarking"> Watermarking option<br />
<input type="submit" name="Upload" value="Upload File">
</form></center>
</body>
</html>

Closed Thread  
Page 1 of 3 1 2 3 >


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed