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"; } ?> Link to comment https://forums.phpfreaks.com/topic/218781-need-help-upload-few-images/ 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 Link to comment https://forums.phpfreaks.com/topic/218781-need-help-upload-few-images/#findComment-1134685 Share on other sites More sharing options...
Hrvoje Posted November 15, 2010 Author Share Posted November 15, 2010 Its working now, many thanks. Hrvoje Link to comment https://forums.phpfreaks.com/topic/218781-need-help-upload-few-images/#findComment-1134693 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/218781-need-help-upload-few-images/#findComment-1135069 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 Link to comment https://forums.phpfreaks.com/topic/218781-need-help-upload-few-images/#findComment-1135102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.