picture upload

Looking for volunteers to join your project? Need help with a script but can't afford to pay? Want to offer your services as a volunteer to build up your portfolio? This is the place for you...

Moderator: General Moderators

Post Reply
KLaas
Forum Newbie
Posts: 3
Joined: Wed Jan 21, 2004 3:51 pm

picture upload

Post by KLaas »

Hi there I've got this script that should upload three pictures and also write their pad names into the database. I got is from sombody else but I don't really know how to change it to fit my needs. I hope anyone does here.

Thank you anyway

Code: Select all

<?php

$aantalups="3"; 
for($i=0; $i<$aantalups; $i++){ 
$blok .= "Plaatje: <input type='file' name='imagesource[]' class='tekst' size='10'> omschrijving: <input type='text' name='omschrijving[]' class='tekst' size='20'><br>"; 
} 

echo"<form name='uploaden' method='post' action='$PHP_SELF' enctype='multipart/form-data'> 
    <INPUT TYPE='hidden' NAME='upload' VALUE='upload'> 
    <INPUT TYPE='hidden' NAME='album' VALUE='".$_GET['album']."'> 
U kunt nu een aantal plaatjes uploaden.<br><br> 
$blok<br><br><input type='submit' value='upload plaatjes' class='tekst'> 
</form>"; 
?>

de upload en bewaar code: 

<? 

$con = mysql_connect("localhost", "xxxx_x", "xxx")or die("Connect Error: ".mysql_error()); 
$db="xxxx_com_1"; 
mysql_select_db($db, $con)or die("Connect Error: ".mysql_error()); 

if("".$_POST['upload']."" == 'upload'){ 

for ($i=0; $i<sizeof($HTTP_POST_FILES['imagesource']['name']); $i++) { 

$naam = $HTTP_POST_FILES['imagesource']['name'][$i]; 
$type = $HTTP_POST_FILES['imagesource']['type'][$i]; 
$size = $HTTP_POST_FILES['imagesource']['size'][$i]; 
$omschrijving = $_POST['omschrijving'][$i]; 
$size = round($size / 1024); 
$ext = substr("$naam", -3); 
$naam = uniqid("i"); 
$naam= "$naam".".$ext"; 

$omschrijving = addslashes($omschrijving); 

move_uploaded_file($imagesource[$i], "$systeempad_server/foto/".$_POST['album']."/$naam"); 

$naam = addslashes($naam); 

if($ext != ''){ 

$sql = "INSERT INTO test (foto1) VALUES ('$naam')"; 
mysql_query($sql) or die("Error on line 49<br><hr>" . mysql_error()); 

// alleen een thumbje maken als dit een jpg file is 
    if($ext=='jpg'){ 
    // en even een thumbje maken 
            $photo = imagecreatefromjpeg ("$systeempad_server/foto/".$_POST['album']."/$naam"); 
            $photo_dimensions_width = imagesx ($photo); 
            $photo_dimensions_height = imagesy ($photo); 
            $thumb_dimensions_width = 100; 
            $thumb_dimensions_height = 75; 
             
            //oude gd 1.0 
            $create_thumb = imagecreate ($thumb_dimensions_width, $thumb_dimensions_height); 
            imagecopyresized ($create_thumb, $photo, 0, 0, 0, 0, $thumb_dimensions_width, $thumb_dimensions_height, $photo_dimensions_width, $photo_dimensions_height);   
        ImageJpeg($create_thumb,"$systeempad_server/thumbs/".$_POST['album']."/t_$naam",100); 
    } 
} 
} 

//uploaden gelukt, even melden 
echo" Uploaden gelukt"; 

} 


?>
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

toenglish($above_post);

wow thats confusing!?!?!?!?!?!?
KLaas
Forum Newbie
Posts: 3
Joined: Wed Jan 21, 2004 3:51 pm

Post by KLaas »

I'm not going to translate anything, all you need in the code is english so just don't look at the comments
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

KLaas wrote:I'm not going to translate anything, all you need in the code is english so just don't look at the comments
Although the purpose of comments should be to explain the code ;) - variables names are also in Dutch? so that makes it doubly difficult for people to work with the code.

BTW, I've moved this to the Project Help Wanted/Volunteer Work forum, the PHP - Code forum is intended to help with your own code, not to modify someone else's to fit your needs.

Mac
KLaas
Forum Newbie
Posts: 3
Joined: Wed Jan 21, 2004 3:51 pm

fine bye

Post by KLaas »

fine bye
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Give me a couple of minuuts to have that all translated for you guys.

dutch -> english

Well here it is in [ENGLISH] ;-)
not that everthing which was written in dutch has been translated into english, leaving the code itself untouched

Code: Select all

<?php 

$numberofuploads="3"; 
for($i=0; $i<$numberofuploads; $i++){ 
$blok .= "picture: <input type='file' name='imagesource[]' class='tekst' size='10'> description: <input type='text' name='discription[]' class='tekst' size='20'><br>"; // tekt => text
} 

echo"<form name='uploaden' method='post' action='$PHP_SELF' enctype='multipart/form-data'> 
    <INPUT TYPE='hidden' NAME='upload' VALUE='upload'> 
    <INPUT TYPE='hidden' NAME='album' VALUE='".$_GET['album']."'> 
you can also upload multipul number of pictures.<br><br> 
$blok<br><br><input type='submit' value='uploading pictures' class='tekst'> 
</form>"; 
?> 

// the upload and saving code

<? 

$con = mysql_connect("localhost", "xxxx_x", "xxx")or die("Connect Error: ".mysql_error()); 
$db="xxxx_com_1"; 
mysql_select_db($db, $con)or die("Connect Error: ".mysql_error()); 

if("".$_POST['upload']."" == 'upload'){ 

for ($i=0; $i<sizeof($HTTP_POST_FILES['imagesource']['name']); $i++) { 

$name = $HTTP_POST_FILES['imagesource']['name'][$i]; 
$type = $HTTP_POST_FILES['imagesource']['type'][$i]; 
$size = $HTTP_POST_FILES['imagesource']['size'][$i]; 
$description = $_POST['description'][$i]; 
$size = round($size / 1024); 
$ext = substr("$name", -3);  // ext -> i think this refers to $extension.
$name = uniqid("i"); 
$name= "$name".".$ext"; 

$description = addslashes($description); 

move_uploaded_file($imagesource[$i], "$systempath_server/photo/".$_POST['album']."/$name"); 

$name = addslashes($name); 

if($ext != ''){ 

$sql = "INSERT INTO test (foto1) VALUES ('$name')"; 
mysql_query($sql) or die("Error on line 49<br><hr>" . mysql_error()); 

//-> only make this a thumb(?nail? ) if its a jpg file 
    if($ext=='jpg'){ 
    // making the thumb
            $photo = imagecreatefromjpeg ("$systempath_server/foto/".$_POST['album']."/$name"); 
            $photo_dimensions_width = imagesx ($photo); 
            $photo_dimensions_height = imagesy ($photo); 
            $thumb_dimensions_width = 100; 
            $thumb_dimensions_height = 75; 
              
            //-> Old gd 1.0 
            $create_thumb = imagecreate ($thumb_dimensions_width, $thumb_dimensions_height); 
            imagecopyresized ($create_thumb, $photo, 0, 0, 0, 0, $thumb_dimensions_width, $thumb_dimensions_height, $photo_dimensions_width, $photo_dimensions_height);    
        ImageJpeg($create_thumb,"$systempath_server/thumbs/".$_POST['album']."/t_$name",100); 
    } 
} 
} 

//upload succesful, just reporting 
echo" Upload succesful"; 

} 


?>
Por supuesto y sin culpa.
Post Reply