Hi
I am using this code for upload image.
<table>
<form action="process.php method="POST" enctype="multipart/form-data">
<tr>
<td align="right">Image1 :</td>
<td><input type="file" name="photo1" class="box"> </td>
</tr>
<tr>
<td colspan="2" align=”center”>
<input name="add" type="Submit" id="add" value=" Submit " class="box">
<input type="reset" value="Refresh" class="box">
</td>
</tr>
</form>
</table>
And process.php file have this code <?php
$epoch = date(“U”);
$uploadDir="../images-album/";
if (isset($_FILES['photo1']['name'])) {
$mode = '0777';
$photo1 = $epoch.$_FILES['photo1']['name'];
$image1 = $uploadDir.$photo1;
move_uploaded_file($_FILES['photo1']['tmp_name'],$image1);
chmod ($image1, octdec($mode));
}
$sql = “INSERT INTO tablename (photo1) VALUES (‘$photo1’)”;
$result = mysql_query($sql);
?>
I use above code for upload image.
Problem is that when the form is submitted without a file attached the epoch still gets inserted into the DB.
If any body has idea about it helps me.
5 1766
Hi
I am using this code for upload image.
<table>
<form action="process.php method="POST" enctype="multipart/form-data">
<tr>
<td align="right">Image1 :</td>
<td><input type="file" name="photo1" class="box"> </td>
</tr>
<tr>
<td colspan="2" align=”center”>
<input name="add" type="Submit" id="add" value=" Submit " class="box">
<input type="reset" value="Refresh" class="box">
</td>
</tr>
</form>
</table>
And process.php file have this code <?php
$epoch = date(“U”);
$uploadDir="../images-album/";
if (isset($_FILES['photo1']['name'])) {
$mode = '0777';
$photo1 = $epoch.$_FILES['photo1']['name'];
$image1 = $uploadDir.$photo1;
move_uploaded_file($_FILES['photo1']['tmp_name'],$image1);
chmod ($image1, octdec($mode));
}
$sql = “INSERT INTO tablename (photo1) VALUES (‘$photo1’)”;
$result = mysql_query($sql);
?>
I use above code for upload image.
Problem is that when the form is submitted without a file attached the epoch still gets inserted into the DB.
If any body has idea about it helps me.
Move the mysql queuries inside the IF statement.
Also, read this tutorial for a better image upload.
Hi
I am using this code for upload image.
<table>
<form action="process.php method="POST" enctype="multipart/form-data">
<tr>
<td align="right">Image1 :</td>
<td><input type="file" name="photo1" class="box"> </td>
</tr>
<tr>
<td colspan="2" align=”center”>
<input name="add" type="Submit" id="add" value=" Submit " class="box">
<input type="reset" value="Refresh" class="box">
</td>
</tr>
</form>
</table>
And process.php file have this code <?php
$epoch = date(“U”);
$uploadDir="../images-album/";
if (isset($_FILES['photo1']['name'])) {
$mode = '0777';
$photo1 = $epoch.$_FILES['photo1']['name'];
$image1 = $uploadDir.$photo1;
move_uploaded_file($_FILES['photo1']['tmp_name'],$image1);
chmod ($image1, octdec($mode));
}
$sql = “INSERT INTO tablename (photo1) VALUES (‘$photo1’)”;
$result = mysql_query($sql);
?>
I use above code for upload image.
Problem is that when the form is submitted without a file attached the epoch still gets inserted into the DB.
If any body has idea about it helps me.
isset() will return FALSE if testing a variable that has been set to NULL so when u used the isset then return the true so insert in DB only opec.submission the form check the vaue is not NULL as vell as empty.
so now u can check is(!empty($_FILES['photo1']['name']))
Thanks,
Sandeep Agarwal
I hope this code might help u. pls check it -
<?php
-
$con=mysql_connect("localhost", "root", "simply123") or die("Could not connect: " . mysql_error());
-
mysql_select_db("minedb");
-
-
echo "Epoch is ".$epoch = date(U);
-
$uploadDir="uploads/";
-
-
if($_REQUEST['add'])
-
{
-
if (isset($_FILES['photo1']['name']))
-
{
-
$mode = '0777';
-
if(!empty($_FILES['photo1']['name']))
-
{
-
$photo1 = $epoch.$_FILES['photo1']['name'];
-
}
-
$image1 = $uploadDir.$photo1;
-
move_uploaded_file($_FILES['photo1']['tmp_name'],$image1);
-
chmod ($image1, octdec($mode));
-
-
}
-
-
if(!empty($_FILES['photo1']['name']))
-
{
-
$sql="insert into photo(photoname) values('".$photo1."')";
-
mysql_query($sql) or die(mysql_error());
-
echo "Uploaded";
-
}
-
}
-
?>
-
<body>
-
<form action="upload12.php" method="POST" enctype="multipart/form-data">
-
<table>
-
<tr>
-
<td align="right">Image1 :</td>
-
<td><input type="file" name="photo1" class="box"> </td>
-
</tr>
-
<tr>
-
<td colspan="2" align=”center”>
-
<input name="add" type="Submit" id="add" value=" Submit " class="box">
-
<input type="reset" value="Refresh" class="box">
-
</td>
-
</tr>
-
</form>
-
</table>
-
</body>
-
</html>
by
arunj82
I hope this code might help u. pls check it -
<?php
-
$con=mysql_connect("localhost", "root", "simply123") or die("Could not connect: " . mysql_error());
-
mysql_select_db("minedb");
-
-
echo "Epoch is ".$epoch = date(U);
-
$uploadDir="uploads/";
-
-
if($_REQUEST['add'])
-
{
-
if (isset($_FILES['photo1']['name']))
-
{
-
$mode = '0777';
-
if(!empty($_FILES['photo1']['name']))
-
{
-
$photo1 = $epoch.$_FILES['photo1']['name'];
-
}
-
$image1 = $uploadDir.$photo1;
-
move_uploaded_file($_FILES['photo1']['tmp_name'],$image1);
-
chmod ($image1, octdec($mode));
-
-
}
-
-
if(!empty($_FILES['photo1']['name']))
-
{
-
$sql="insert into photo(photoname) values('".$photo1."')";
-
mysql_query($sql) or die(mysql_error());
-
echo "Uploaded";
-
}
-
}
-
?>
-
<body>
-
<form action="upload12.php" method="POST" enctype="multipart/form-data">
-
<table>
-
<tr>
-
<td align="right">Image1 :</td>
-
<td><input type="file" name="photo1" class="box"> </td>
-
</tr>
-
<tr>
-
<td colspan="2" align=”center”>
-
<input name="add" type="Submit" id="add" value=" Submit " class="box">
-
<input type="reset" value="Refresh" class="box">
-
</td>
-
</tr>
-
</form>
-
</table>
-
</body>
-
</html>
by
arunj82
Don't post full code.
Especially if you're not going to explain it.
isset() will return FALSE if testing a variable that has been set to NULL so when u used the isset then return the true so insert in DB only opec.submission the form check the vaue is not NULL as vell as empty.
so now u can check is(!empty($_FILES['photo1']['name']))
Thanks,
Sandeep Agarwal
Yes...
His IF statement will work fine.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: dave |
last post by:
Hello there,
I am at my wit's end ! I have used the following script succesfully to
upload an image to my web space. But what I really want to be able to do is
to update an existing record in a...
|
by: Tim::.. |
last post by:
Can someone please tell me why I keep getting an error saying the page cannot
be displayed in my ASP.NET app. If I upload a file that is under approx 3mb
then it works file but as soon as I try to...
|
by: David Lozzi |
last post by:
Howdy,
I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders!
Now I am making a public function that will take the...
|
by: SEMIH DEMIR |
last post by:
Sitelerden birinde verilen yabancý kaynakli bir scriptti duzenledim
yanlýz birseyin içinden bir turlu cýkamadým iþin aslý ilk defa
persistin upload componentini kullanacam yanlýz suanki haliyle...
|
by: Jim Michaels |
last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going
on here?
$_POST=C
$_POST=C
$_POST=C
$_POST=C:\\www\\jimm\\images\\bg1.jpg
$_FILES=
$_FILES=
$_FILES=
|
by: Wayne Smith |
last post by:
I've come up against a major headache that I can't seem to find a solution
for but I'm sure there must be a workaround and I would really be grateful
of any help.
I'm currently building a web...
|
by: kksandeep |
last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help
the script i found is some helpful but not too that i need
...
|
by: kksandeep |
last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help
the script i found is some helpful but not too that i need
...
|
by: xx75vulcan |
last post by:
Hi,
I've got a PHP Upload Form that works great, unless that is, the image
your uploading has been modified through a photo editing software.
Example: if I upload the image straight from a...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |