Jump to content

Need help - Upload few images?


Hrvoje

Recommended Posts

Hello...

 

I have some simple code but no ideas for upload another image??

PHP stores image name in database but there is no second picture uploaded in the images/ folder.

 

Pls help.

Thanks

 

if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "<strong>Slika:</strong> " . $_FILES["file"]["name"] . "<br />";
    echo "<strong>Format slike:</strong> " . $_FILES["file"]["type"] . "<br />";
    echo "<strong>Velicina:</strong> " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "<strong>Temp file:</strong> " . $_FILES["file"]["tmp_name"] . "<br />";



//  here is mistake???

      move_uploaded_file($_FILES["file"]["tmp_name"],
      "images/" . $_FILES["file"]["name"]);

//
      


$sql="INSERT INTO test (name, something, slika, slika2)
VALUES ('".$_POST['name']."', '".$_POST['something']."', '".$_FILES['file']['name']."', '".$_FILES['slika1']['name']."')";

if (mysql_query($sql))

{

    echo "Sucess";

} else {

    echo "Error" . mysql_error();

}
}
}
  else
  {
  echo "Invalid file";
  }
?>  

Link to comment
Share on other sites

similar but little different try using this method:

 

$filename = $_FILES['upload']['name'];

if (move_uploaded_file($_FILES['upload']['tmp_name'], "../all_plants_img/$filename")) {

echo 'success image uploaded';

}

 

plus better to insert image info into db first then use

mysql_insert_id()

to get the int id and rename the image with the same number for easier reference

 

 

 

www.mymatesplace.com.au

Link to comment
Share on other sites

Again my mistake sorry...

Does not work anymore:

 

Posting image name in dba but not upload images, only first image is uploaded .$_FILES['file']['name']

 

HTML input is 100% ok!

 

PHP:

 

<?php

include "database.php";




if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "<strong>Slika:</strong> " . $_FILES["file"]["name"] . "<br />";
    echo "<strong>Format slike:</strong> " . $_FILES["file"]["type"] . "<br />";
    echo "<strong>Velicina:</strong> " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "<strong>Temp file:</strong> " . $_FILES["file"]["tmp_name"] . "<br />";



    //   My old way...

    //   move_uploaded_file($_FILES["file"]["tmp_name"],
    //   "images/upload/" . $_FILES["file"]["name"]);
  


$filename = $_FILES['file']['name'];

if (move_uploaded_file($_FILES['file']['tmp_name'], "images/upload/$filename")) {

echo 'success image uploaded';

}

$sql="INSERT INTO artikli (ime_artikla, opis_artikla, grupacija, raspoloziv, slika, slika1, slika2, slika3, slika4, slika5)
VALUES ('".$_POST['ime_artikla']."', '".$_POST['opis_artikla']."', '".$_POST['grupacija']."', '".$_POST['raspoloziv']."', '".$_FILES['file']['name']."', '".$_FILES['slika1']['name']."', '".$_FILES['slika2']['name']."', '".$_FILES['slika3']['name']."', '".$_FILES['slika4']['name']."', '".$_FILES['slika5']['name']."')";

if (mysql_query($sql))

{

echo "Success";

} else {

echo "Error" . mysql_error();

}
}
}
  else
  {
  echo "Invalid file";
  }
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.