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,472
There are 1744 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 2 of 3 < 1 2 3 >
    Thread tools Search this thread Display Modes  
08-08-2006, 02:26 PM
#11
Lang is offline Lang
Status: I'm new around here
Join date: Jul 2006
Location:
Expertise:
Software:
 
Posts: 17
iTrader: 0 / 0%
 

Lang is on a distinguished road

  Old

Uhm, first off, let's see the form? Do you ahve the proper encryption?

Code:
<form enctype="multipart/form-data">
</form>
if ya don't have that enctype, it won't work.

08-08-2006, 02:46 PM
#12
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 thx now it's working now i can fix some bugs in it

08-08-2006, 03:01 PM
#13
Lang is offline Lang
Status: I'm new around here
Join date: Jul 2006
Location:
Expertise:
Software:
 
Posts: 17
iTrader: 0 / 0%
 

Lang is on a distinguished road

  Old

No problem, if you download the documentation on PHP and search for upload, the first result would've told you your error from the beginning.

08-08-2006, 03:12 PM
#14
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

oh didn't knew it, know I know in other cases
but I got another problem, I know I'm not good at php, just started but
Watermark and thumbnail won't work
I don't see a watermark and no file in /test/images/thumb
PHP Code:
<?php
define 
('THUMBWIDTH'100);
define ('THUMBHEIGHT'100);
define ('WATERMARK''ImagePillage' )

function 
CreateThumb($src) {
    
copy$src"$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'] . "/test/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) {
    
$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 enctype="multipart/form-data" 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, 03:40 PM
#15
Lang is offline Lang
Status: I'm new around here
Join date: Jul 2006
Location:
Expertise:
Software:
 
Posts: 17
iTrader: 0 / 0%
 

Lang is on a distinguished road

  Old

I thought i'd point out 8mb is 8192000 bytes. Not what you have.
1kb = 1024bytes
1024 x 1000 = 1024000
1024000 = 1MB
1024000 x 8 = 8192000
8192000 = 8MB


As for your files not showing up, the value returned from checkboxes is "on" or "off". Not 1 or 0 so you have to alter your script accordingly.

08-08-2006, 04:55 PM
#16
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 now i get some errors
when i check thumbnails I get

Warning: copy(''. '/thumb/' . '') [function.copy]: failed to open stream: No such file or directory in
error on line 7
it's the copy( $src thingy
and when i do watermark it works but It doesn't put a text on it it's just the same as normal uploading
PHP Code:
<?php
define 
('THUMBWIDTH'100);
define ('THUMBHEIGHT'100);
define ('WATERMARK''ImagePillage' );

function 
CreateThumb($src) {
    
copy$src"$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'] . "/test/images/";
    
$MaxFileSize 8192000;
    
$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) {
    
$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( 
$upload ) {
                if( 
$Thumb ) {
                    
$file "$upload_dir$new_filename";
                    
CreateThumb($file);
                }
                if( 
$Water) {
                    
$file "$upload_dir$new_filename";
                    
CreateWatermark($file);
                }
                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 enctype="multipart/form-data" 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, 11:51 PM
#17
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 php doesn't show any errors anymore it only doesn't change the files

08-09-2006, 01:58 PM
#18
Lang is offline Lang
Status: I'm new around here
Join date: Jul 2006
Location:
Expertise:
Software:
 
Posts: 17
iTrader: 0 / 0%
 

Lang is on a distinguished road

  Old

Make sure you CHMOD the folders where you want to upload the pictures. CHMOD them with an FTP client to 777.

By the way, I suggest you do something like this for your checkboxes:
PHP Code:
<?
    $Thumb 
0;
    if (
$_POST['thumb'] == "on"){
     
$Thumb 1;
    }
    
$Water 0;
    if (
$_POST['water'] == "on"){
     
$Water 1;
    }

    if (
$Thumb == 1){
      
//sdfasdfsadf
    
}
    if (
$Water == 1){
      
//sdfasdfsadf
    
}
?>

08-09-2006, 05:29 PM
#19
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

uploading works fine,
I just added your code to it
but my problem still is it won't change the image size and/or give a watermark to it
this is my code pls hel me with this
PHP Code:
<?php
define 
('THUMBHEIGHT'100);
define ('THUMBHEIGHT'100);
define ('WATERMARK''ImagePillage' );

function 
CreateThumb($src$filename) {
    
$thumbfilename $_SERVER['DOCUMENT_ROOT'] . "/test/images/thumb/$filename";
    
copy$src$thumbfilename );
    
$src $thumbfilename;
    list(
$width$height$type$attr) = getimagesize($src);
    
$img imagecreatefromstring(file_get_contents($src));
    
$tmp imagecreatetruecolor(100100);
    
imagecopyresized($tmp$img0000100100$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'] . "/test/images/";
    
$MaxFileSize 8192000;
    
$filename $_FILES['file']['name'];
    
$filesize $_FILES['file']['size'];
    
$filetmpname $_FILES['file']['tmp_name'];
    
$allowed_types = array( "jpg""gif""png" );
    
$filetype substr($filename, -33);
    
$Thumb 0;
    
$Water 0;
    
    if(
$filename) {
    
$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 (
$_POST['Thumbnail'] == "on") {
                
$Thumb 1;
            }
             if (
$_POST['Watermark'] == "on") {
                 
$Water 1;
            }
            if( 
$upload ) {
                if( 
$Thumb == ) {
                    
$file "$upload_dir$new_filename";
                    
CreateThumb($file$new_filename);
                }
                if( 
$Water == 1) {
                    
$file "$upload_dir$new_filename";
                    
CreateWatermark($file);
                }
                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 enctype="multipart/form-data" 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"> Watermark option<br />
<input type="submit" name="Upload" value="Upload File">
</form></center>
</body>
</html>

08-10-2006, 02:34 PM
#20
Lang is offline Lang
Status: I'm new around here
Join date: Jul 2006
Location:
Expertise:
Software:
 
Posts: 17
iTrader: 0 / 0%
 

Lang is on a distinguished road

  Old

Ok so i've narrowed it down to your imagecreatefromtruecolor() function.

You need to check what type the image is then use the appropriate function.

For JPG fiels its imagecreatefromjpeg(), for GIF files its imagecreatefromgif(). Ect ect

you really should try downloading the manual, that's how I'm helping you at the moment.

Closed Thread  
Page 2 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