473,385 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Upload Image Probelm

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.
Jan 30 '08 #1
5 1766
Markus
6,050 Expert 4TB
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.
Jan 30 '08 #2
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
Jan 30 '08 #3
arunj82
15
I hope this code might help u. pls check it

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect("localhost", "root", "simply123") or die("Could not connect: " . mysql_error());
  3. mysql_select_db("minedb");
  4.  
  5. echo "Epoch is ".$epoch = date(U);
  6. $uploadDir="uploads/";
  7.  
  8. if($_REQUEST['add'])
  9. {
  10.                     if (isset($_FILES['photo1']['name']))
  11.                     {
  12.                             $mode = '0777';
  13.                             if(!empty($_FILES['photo1']['name']))
  14.                             {
  15.                                     $photo1 = $epoch.$_FILES['photo1']['name'];
  16.                             }
  17.                             $image1 = $uploadDir.$photo1;
  18.                             move_uploaded_file($_FILES['photo1']['tmp_name'],$image1);
  19.                             chmod ($image1, octdec($mode));
  20.  
  21.                     }
  22.  
  23.                     if(!empty($_FILES['photo1']['name']))
  24.                     {
  25.                             $sql="insert into photo(photoname) values('".$photo1."')";
  26.                              mysql_query($sql) or die(mysql_error());
  27.                             echo "Uploaded";
  28.                     }
  29. }
  30. ?>
  31. <body>
  32. <form action="upload12.php" method="POST" enctype="multipart/form-data">
  33. <table>
  34. <tr>
  35. <td align="right">Image1 :</td>
  36. <td><input type="file" name="photo1" class="box"> </td>
  37. </tr>
  38. <tr>
  39. <td colspan="2" align=”center”>
  40. <input name="add" type="Submit" id="add" value=" Submit " class="box">
  41. <input type="reset" value="Refresh" class="box">
  42. </td>
  43. </tr>
  44. </form>
  45. </table>
  46. </body>
  47. </html>
by
arunj82
Jan 30 '08 #4
Markus
6,050 Expert 4TB
I hope this code might help u. pls check it

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $con=mysql_connect("localhost", "root", "simply123") or die("Could not connect: " . mysql_error());
  3. mysql_select_db("minedb");
  4.  
  5. echo "Epoch is ".$epoch = date(U);
  6. $uploadDir="uploads/";
  7.  
  8. if($_REQUEST['add'])
  9. {
  10.                     if (isset($_FILES['photo1']['name']))
  11.                     {
  12.                             $mode = '0777';
  13.                             if(!empty($_FILES['photo1']['name']))
  14.                             {
  15.                                     $photo1 = $epoch.$_FILES['photo1']['name'];
  16.                             }
  17.                             $image1 = $uploadDir.$photo1;
  18.                             move_uploaded_file($_FILES['photo1']['tmp_name'],$image1);
  19.                             chmod ($image1, octdec($mode));
  20.  
  21.                     }
  22.  
  23.                     if(!empty($_FILES['photo1']['name']))
  24.                     {
  25.                             $sql="insert into photo(photoname) values('".$photo1."')";
  26.                              mysql_query($sql) or die(mysql_error());
  27.                             echo "Uploaded";
  28.                     }
  29. }
  30. ?>
  31. <body>
  32. <form action="upload12.php" method="POST" enctype="multipart/form-data">
  33. <table>
  34. <tr>
  35. <td align="right">Image1 :</td>
  36. <td><input type="file" name="photo1" class="box"> </td>
  37. </tr>
  38. <tr>
  39. <td colspan="2" align=”center”>
  40. <input name="add" type="Submit" id="add" value=" Submit " class="box">
  41. <input type="reset" value="Refresh" class="box">
  42. </td>
  43. </tr>
  44. </form>
  45. </table>
  46. </body>
  47. </html>
by
arunj82
Don't post full code.
Especially if you're not going to explain it.
Jan 30 '08 #5
Markus
6,050 Expert 4TB
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.
Jan 30 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
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...
2
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...
15
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...
0
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...
4
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=
9
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...
3
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 ...
1
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 ...
7
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...
0
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...
0
isladogs
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...
0
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...
0
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,...
0
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$) { } ...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.