Hrvoje Posted November 15, 2010 Share Posted November 15, 2010 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"; } ?> Quote Link to comment Share on other sites More sharing options...
wigpip Posted November 15, 2010 Share Posted November 15, 2010 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 Quote Link to comment Share on other sites More sharing options...
Hrvoje Posted November 15, 2010 Author Share Posted November 15, 2010 Its working now, many thanks. Hrvoje Quote Link to comment Share on other sites More sharing options...
Hrvoje Posted November 16, 2010 Author Share Posted November 16, 2010 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"; } ?> Quote Link to comment Share on other sites More sharing options...
litebearer Posted November 16, 2010 Share Posted November 16, 2010 uploading multiple images http://www.plus2net.com/php_tutorial/php_multi_file_upload.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.