I need a little help. I have 2 question:
1. How can I upload multiple photos whitout copy-paste the cod without disturb the autorename code.
2. How can I set error to stop upload if one photo does not respect the quest (size and type).
This si the code that I use....
This inserts data to mysql db, and upload photo (one for now), rename the uploaded photos, and patch the name and insert it into mysql db.
include 'connection.php';
$tranz = $_POST[inputTranzactie];
$imobil = $_POST[inputImobil];
$local = $_POST[inputLocalitate];
$desc = $_POST[inputDescriere];
$pret = $_POST[inputPret];
define ("MAX_SIZE","1000");
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST['submit'])) {
$image=$_FILES['image1']['name'];
if ($image) {
$filename = stripslashes($_FILES['image1']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
$newrecord1 = "<h3>Unknown extension!</h3>";
$errors=1;
}
else
{
$size=filesize($_FILES['image1']['tmp_name']);
$image_name=time().'.'.$extension;
$newname="upload/".$image_name;
$copied = copy($_FILES['image1']['tmp_name'], $newname);
}}}
if(isset($_POST['submit']) && !$errors)
{
$newrecord2 = "<h3>File Uploaded Successfully! Try again!</h3>";
}
if(!$_POST['submit']) {
echo"Insert data";
}else{
mysql_query("INSERT INTO table (`ID`,`imobil`,`tranzactie`,`descriere`,`pret`,`localitate`,`poza1`)
VALUES(NULL,'$imobil','$tranz','$desc','$pret','$local','$newname')") or die(mysql_error());
echo "Adaugare reusita!";
}
Thank you
upload multiple photos...
Moderator: General Moderators
Re: upload multiple photos...
Use something like_user wrote:1. How can I upload multiple photos whitout copy-paste the cod without disturb the autorename code.
Code: Select all
foreach ($_FILES as $file)Why not just resize the image?_user wrote:2. How can I set error to stop upload if one photo does not respect the quest (size and type).
Re: upload multiple photos...
I don't understand first part...
how should looklike the code?
What I ment to ask is.. how can I stop the update data to mysql if a picture uploaded dosn`t respect the quest.
Now, if I insert data to fields, and upload a picture (with other type, or biger size), the data is insert into mysql db, but the picture upload stops, and what I want is if the picture is not good, stop insert data into mysql.. and not insert it without the picture...
And how can I resize the uploaded pictures?
how should looklike the code?
What I ment to ask is.. how can I stop the update data to mysql if a picture uploaded dosn`t respect the quest.
Now, if I insert data to fields, and upload a picture (with other type, or biger size), the data is insert into mysql db, but the picture upload stops, and what I want is if the picture is not good, stop insert data into mysql.. and not insert it without the picture...
And how can I resize the uploaded pictures?