the code below will upload image and insert the image name and other variable into the database but i dont want the upload feild to post a blank field and also not
to allow any image which is not gif, jpeg and png. the code that i have that can do the folowing are if($_FILES['images']['size'] == 0){ and if (!eregi("^([A-Za-z0-9]+)\.jpg|\.gif|\.png$", $logoname))
but the problem is i dont know where to insert it in the code below (upload.php) i try inserting it but did not working -
<?php
-
-
if (isset($_POST['submit'])) {
-
If(empty($_POST['fristname']) OR empty($_POST['emaill'])OR empty($_POST['category'])){
-
echo '<font size="2" color="#FF0000">Please fill in all the required fields!</font>';
-
}else{
-
-
$logoname = $_FILES['images']['name'];
-
$tmpname = $_FILES['images']['tmp_name'];
-
$logosize = $_FILES['images']['size'];
-
$logotype = $_FILES['images']['type'];
-
-
-
-
while(list($key,$value) = each($_FILES['images']['name'])){
-
if(!empty($value)) {
-
$logoname = $value;
-
$logoname = str_replace(" ","_",$logoname);// Add _ inplace of blank space in file name, you can remove this line
-
-
$add = "./company_logo/$logoname";
-
echo "<font size='2' color='#FF0000'>your company is added successfully</font>";
-
echo "<br>";
-
-
copy($_FILES['images']['tmp_name'][$key], $add);
-
chmod("$add",0777);
-
}
-
-
$image = new SimpleImage();
-
$image->load("$add");
-
$image->resize(100,100);
-
$image->save("$add");
-
-
$fristname = ($_POST['fristname']);
-
$email = ($_POST['email']);
-
$category = ($_POST['category']);
-
-
mysql_query("INSERT INTO companylogourl (fristname, imagename, email, category)
-
VALUES('$fristname', '$logoname', '$email', '$category')") or die(mysql_error());
-
}
-
}
-
}
-
-
?>
-
3 2231
You want to do it as early as possible to avoid doing stuff that isn't necessary if the file isn't correct. So, I would suggest add your conditional statements immediately after you create the image information variables (lines 8 - 11).
i have insert the conditional statement between line 8 and 11 but is still giving me error when i try to post a blank field i will appreciate if you help me adjust my code -
<?php
-
-
if (isset($_POST['submit'])) {
-
If(empty($_POST['fristname']) OR empty($_POST['emaill'])OR empty($_POST['category'])){
-
echo '<font size="2" color="#FF0000">Please fill in all the required fields!</font>';
-
}else{
-
-
if($_FILES['images']['size'] == 0){
-
echo '<font size="2" color="#FF0000">Please upload your company logo</font>';
-
}
-
if (!eregi("^([A-Za-z0-9]+)\.jpg|\.gif|\.png$", $logoname)){
-
echo '<font size="2" color="#FF0000">invalid image format</font>';
-
}
-
$logoname = $_FILES['images']['name'];
-
$tmpname = $_FILES['images']['tmp_name'];
-
$logosize = $_FILES['images']['size'];
-
$logotype = $_FILES['images']['type'];
-
-
-
-
while(list($key,$value) = each($_FILES['images']['name'])){
-
if(!empty($value)) {
-
$logoname = $value;
-
$logoname = str_replace(" ","_",$logoname);// Add _ inplace of blank space in file name, you can remove this line
-
-
$add = "./company_logo/$logoname";
-
echo "<font size='2' color='#FF0000'>your company is added successfully</font>";
-
echo "<br>";
-
-
copy($_FILES['images']['tmp_name'][$key], $add);
-
chmod("$add",0777);
-
}
-
-
$image = new SimpleImage();
-
$image->load("$add");
-
$image->resize(100,100);
-
$image->save("$add");
-
-
$fristname = ($_POST['fristname']);
-
$email = ($_POST['email']);
-
$category = ($_POST['category']);
-
-
mysql_query("INSERT INTO companylogourl (fristname, imagename, email, category)
-
VALUES('$fristname', '$logoname', '$email', '$category')") or die(mysql_error());
-
}
-
}
-
}
-
-
?>
-
Hi when you check for if a file exists to be uploaded, if its not then you should exit() or redirect or skip all the next part. Currently it looks like you are throwing an error back but still attempting to do the upload.
So here: - if($_FILES['images']['size'] == 0){
-
echo '<font size="2" color="#FF0000">Please upload your company logo</font>';
-
///// DO SOMETHING HERE to stop the process....
-
}
Post back if you are still stuck.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John |
last post by:
How do I prevent blank data from being entered into a table?
For instance, the user fills out a form, but if a field is left blank, then
the entire entry won't be filled in. This isn't...
|
by: Ravi |
last post by:
I have a webpage(with a text field and a button) which prompts for a
local file and attempts to load the file in the window if the user
clicks on the button. The javascript code onClick event uses...
|
by: Brian |
last post by:
Hello -
Is there a way to prevent the user from creating a blank row at the
bottom of a datagrid? I want a read only grid that allows the user to
view data but not select specific cells or...
|
by: Charles Law |
last post by:
When I click a button I don't want the click event to fire. Is this
possible?
In fact, what I would really like is to be able to intercept the click
event, perform some action, and then prevent...
|
by: Jake Barnes |
last post by:
At a certain point in my code, I need to blank the value in a file
input. The situation comes up when a user first thinks they want to
upload something from their harddrive, but then they change...
|
by: Larry Bud |
last post by:
I rarely crosspost, but this affects both ASP and Javascript
REALLY odd bug that I ran across in ASP 3.0. I have an input type of
file, user clicks browse, then places his cursor in the...
|
by: groups2 |
last post by:
When you press the down key while in an input field the default
behavior for some event creates a dropdown of the previously input
text.
What event creates that behavior and how do I stop it ?
...
|
by: DavidPr |
last post by:
I'm creating (trying to create) a picture gallery for my website.
The script is not working. I've been working on it now for about 80 hours with no success. My php skills aren't very good.
This...
|
by: Mani |
last post by:
Hi
I have created one sample php script to upload excel sheets of very
bigger sizes. Also the process happening with each records given in
the excel sheets is bit complex. To allow bigger sizes,...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
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: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |