Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Images

Image upload script

images php coding issues or problems here.

Moderators: macek, egami, gesf

Image upload script

Postby dejobse » Tue Oct 30, 2012 5:35 am

Hye guys,
Im new here and i'm allready having a problem :o


my upload script wont work and i cant figure it out, so can you help me?

my php code:
Code: Select all
<?php
$upload_dir   = "files/users/$UID/"; // upload path

#UPLOAD IMAGES
for ($i=1; $i<=3; $i++)
  {
   $upload_dir = $upload_dir . basename( $_FILES['uplimg' . $i]['name']);
   
   if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $upload_dir)) {
   
   } else{
       echo "Woops, try again";
       echo basename( $_FILES['uplimg' . $i]['name']) ;
   }
}   
?>


The $UID is the user id, every user has his own folder where the pictures "are" saved.


the form:

Code: Select all
Afbeelding 1<br />
<input type="file" name="uplimg1"><br />
Afbeelding 2<br />
<input type="file" name="uplimg2"><br />
Afbeelding 3<br />
<input type="file" name="uplimg3"><br />



I hope you can help me out.

greetz
dejobse
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Oct 30, 2012 5:29 am

Re: Image upload script

Postby JBharati » Sun Nov 11, 2012 8:31 pm

<?php

//properties of the uploaded file
$name= $_FILES["myfile"]["name"];
$type= $_FILES["myfile"]["type"];
$size= $_FILES["myfile"]["size"];
$temp= $_FILES["myfile"]["temp_name"];
$error= $_FILES["myfile"]["error"];

if ($error > 0)
die("Error uploading file! code $error.");
else
{
if($type=="image/png" || $size > 2000000)//condition for the file
{
die("Format not allowed or file size too big!");
}
else
{
move_uploaded_file($temp, "uploaded/" .$name);
echo "Upload complete!";
}
}

?>
please try this i hope it will work
JBharati
New php-forum User
New php-forum User
 
Posts: 1
Joined: Sun Nov 11, 2012 1:05 am


Return to PHP coding => Images

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.