4
Contributors
8
Replies
12
Views
8 Years
Discussion Span
Last Post by kiranhg.2008
0
<?php
//edit this
$_max_file_size = '3000000'; //file size in bytes.
$upload_dir = "somefolder/"; //upload folder..chmod to 777
$_i = "1";                //number of files to upload at one time
//end edit


echo "<table width=100% border=0 cellpadding=0 cellspacing=0>";
echo "<form enctype='multipart/form-data' action='?do=upload' method='post' style=\"margin: 0px;\">";
echo "<tr><td><input type='hidden' name='MAX_FILE_SIZE' value='" . $_max_file_size , "'></td></tr>";
if($_GET != 'upload')
{
echo "<tr><td class=redtext>Photo Must Be 250px W by 250px H and in .JPG or .GIF format.</td></tr>";
echo "<tr><td>&nbsp;</td></tr>";
echo "<tr><td class=bodytext>Choose your image:<br>";
//show number of files to select
For($i=0; $i <= $_i-1;$i++)
{
echo "<input name='file" . $i . "' type='file'></td></tr>";
}
echo "<tr><td class=bodytext><input type=submit name=Submit value=\"Upload Photo\" style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; BACKGROUND-COLOR: #5E6456; COLOR: #ffffff;\"></td></tr>";
}


if($_GET == 'upload')
{
//upload all the fields until done
For($i=0; $i <= $_i-1; $i++)
{
//file with the upload folder
$target_path = $upload_dir . basename($_FILES);
$target_path = str_replace (" ", "", $target_path);
//actual file name with the random number
$_file_name = basename($_FILES);
$_file_name = str_replace (" ", "", $_file_name);
//do not upload the 'left blank' fields
if(basename($_FILES) != '')
{
if(move_uploaded_file($_FILES, $target_path))
{
//uploaded successfuly
$_uploaded=1;
}
else
{
//error uploading
$_error=1;
}
}
else
{
$_check=$_check+1;
}


}


//file(s) did upload
if($_uploaded == '1')
{
$_uploaded=0;
$adID = $_GET;


mysql_query("update tbl_whatever set photo = '".$_file_name."' WHERE whatever = '$whatever ");


}
//file uploaded?
if($_error == '1')
{
$_error=0;
echo "<div class=redtext>There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";
}
//user selected a file?
if($_check == $_i)
{
$_check=0;
echo "<div class=redtext>Select a file first than click 'Upload File'</div>";
}
}
echo "</td></tr>";


?>
</table>

Edited by happygeek: fixed formatting

-1

this is workin with localdatabase.....prob is i cant upload photo name to online database.....pls help me im the begginer

Edited by Nick Evan: Fixed formatting

-1
<?php
mysql_connect("localhost", "db_username_here", "db_password_here") or die(mysql_error());
mysql_select_db("yourdbname") or die(mysql_error());
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$query = "SELECT ID FROM agents WHERE username = '$username'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$row = mysql_fetch_array($result);
$owner = $row['ID'];
$uploadDir = 'images/';

if(isset($_POST['submit']))
{
$fileName = $_FILES['file']['name'];
$tmpName  = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading <strong>file</strong>";
exit;
}

if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
    $filePath = addslashes($filePath);
}

$result = mysql_query("UPDATE agents SET photo='images/$fileName' WHERE id='$owner'") 
or die(mysql_error());  

echo "$fileName <h1>Success!</h1> You have successfully added a Profile Photo. Please click <a href=index.php>here </a><br><br><br>";
}
else
{
echo" 
<form name=Image enctype=multipart/form-data method=POST>
<table cellspacing=2 cellpadding=2 border=0>
<tr><td>Image: </td><td><input type=file name=file accept=image/gif, image/jpeg, image/x-ms-bmp, image/x-png size=26 class=textbox /></td></tr>
 <tr><td> </td><td><input type=submit name=submit value=Upload class=button /></td></tr></table>
</form><br>";
}
?>
</div><div class="right_handler"><b>Search ID</b><br /><form action="tree.php" method="get"><input type="text" name="cue" size="25" /> <input type="submit" value="Submit" /></form></div>

Be sure to create a folder named "images" in the same directory where this script runs..

0
<?php



$upload_dir = "d:/xampp/htdocs/images/"; //upload folder..chmod to 777
$_i = "1"; //number of files to upload at one time


if($_POST['Submit'] == 'Upload')
{

For($i=0; $i <= $_i-1; $i++)
{
$target_path = $upload_dir . basename($_FILES['file' . $i]['name']);
$target_path = str_replace (" ", "", $target_path);
$_file_name = basename($_FILES['file' . $i]['name']);
$_file_name = str_replace (" ", "", $_file_name);

if(basename($_FILES['file' . $i]['name']) != '')
{
if(move_uploaded_file($_FILES['file' . $i]['tmp_name'], $target_path))
{
$_uploaded=1;
}
else
{
$_error=1;
}
}
else
{
$_check=$_check+1;
}
}

if($_uploaded == '1') 
{
$_uploaded=0;
//$adID = $_GET['adID'];

//$Category = $_GET['Category'];


$link = mysql_connect("67.220.196.234","hassaninfo","9845098450") or die("Couldn't make connection.");
$db = mysql_select_db("hassaninfo", $link) or die("Couldn't select database");
$lo=$_GET['id'];
//echo $_file_name;
//echo $lo;
 mysql_query("update users set photo = "$_file_name" where `id`='$lo'") or die("error");

//header("Location: ksuc.php");
}


if($_error == '1')
{
$_error=0;
echo "<div class=redtext>There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";
}

if($_check == $_i)
{
$_check=0;
echo "<div class=redtext>Select a file first than click 'Upload File'</div>";
}
}
echo "</td></tr>";

?>






<table width=100% border=0 cellpadding=0 cellspacing=0>
<form enctype='multipart/form-data' action='' method='post' style=\"margin: 0px;\">
<tr><td><input type='hidden' name='MAX_FILE_SIZE' value='3000000'></td></tr>
<tr><td class=redtext>Photo Must Be 250px W by 250px H and in .JPG or .GIF format.</td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td class=bodytext>Choose your image:<br>
<?php
For($i=0; $i <= $_i-1;$i++)
{
echo "<input name='file" . $i . "' type='file'></td></tr>";
}
echo "<tr><td class=bodytext><input type=submit name=Submit value='Upload' style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; BACKGROUND-COLOR: #5E6456; COLOR: #ffffff;\"></td></tr>";
?>
</table>

i taking id as a primary key and it is auto increament.....i get that id value to this php page by get method....but in update query in this not updating the database ....can u pls suggest me pls....i just want to add ads to database so user send photo......his photo name his not updatin in database.....if u code pls send me or give me advice.....

Edited by Nick Evan: Fixed formatting

0
<?php



$upload_dir = "d:/xampp/htdocs/images/"; //upload folder..chmod to 777
$_i = "1"; //number of files to upload at one time


if($_POST['Submit'] == 'Upload')
{

For($i=0; $i <= $_i-1; $i++)
{
$target_path = $upload_dir . basename($_FILES['file' . $i]['name']);
$target_path = str_replace (" ", "", $target_path);
$_file_name = basename($_FILES['file' . $i]['name']);
$_file_name = str_replace (" ", "", $_file_name);
$photo = $_file_name;

if(basename($_FILES['file' . $i]['name']) != '')
{
if(move_uploaded_file($_FILES['file' . $i]['tmp_name'], $target_path))
{
$_uploaded=1;
}
else
{
$_error=1;
}
}
else
{
$_check=$_check+1;
}
}

if($_uploaded == '1')
{
$_uploaded=0;
//$adID = $_GET['adID'];

//$Category = $_GET['Category'];


$link = mysql_connect("67.220.196.234","hassaninfo","9845098450") or die("Couldn't make connection.");
$db = mysql_select_db("hassaninfo", $link) or die("Couldn't select database");
$lo=$_GET['id'];
//echo $_file_name;
//echo $lo;
mysql_query("update users set photo = "$photo" where id = '$lo'") or die("error");

//header("Location: ksuc.php");
}


if($_error == '1')
{
$_error=0;
echo "<div class=redtext>There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";
}

if($_check == $_i)
{
$_check=0;
echo "<div class=redtext>Select a file first than click 'Upload File'</div>";
}
}
echo "</td></tr>";

?>






<table width=100% border=0 cellpadding=0 cellspacing=0>
<form enctype='multipart/form-data' action='' method='post' style=\"margin: 0px;\">
<tr><td><input type='hidden' name='MAX_FILE_SIZE' value='3000000'></td></tr>
<tr><td class=redtext>Photo Must Be 250px W by 250px H and in .JPG or .GIF format.</td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td class=bodytext>Choose your image:<br>
<?php
For($i=0; $i <= $_i-1;$i++)
{
echo "<input name='file" . $i . "' type='file'></td></tr>";
}
echo "<tr><td class=bodytext><input type=submit name=Submit value='Upload' style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; BACKGROUND-COLOR: #5E6456; COLOR: #ffffff;\"></td></tr>";
?>
</table>
0
<?php



$upload_dir = "d:/xampp/htdocs/images/"; //upload folder..chmod to 777
$_i = "1"; //number of files to upload at one time


if($_POST['Submit'] == 'Upload')
{

For($i=0; $i <= $_i-1; $i++)
{
$target_path = $upload_dir . basename($_FILES['file' . $i]['name']);
$target_path = str_replace (" ", "", $target_path);
$_file_name = basename($_FILES['file' . $i]['name']);
$_file_name = str_replace (" ", "", $_file_name);
$photo = $_file_name;

if(basename($_FILES['file' . $i]['name']) != '')
{
if(move_uploaded_file($_FILES['file' . $i]['tmp_name'], $target_path))
{
$_uploaded=1;
}
else
{
$_error=1;
}
}
else
{
$_check=$_check+1;
}
}

if($_uploaded == '1')
{
$_uploaded=0;
//$adID = $_GET['adID'];

//$Category = $_GET['Category'];


$link = mysql_connect("67.220.196.234","hassaninfo","9845098450") or die("Couldn't make connection.");
$db = mysql_select_db("hassaninfo", $link) or die("Couldn't select database");
$lo=$_GET['id'];
//echo $_file_name;
//echo $lo;
mysql_query("update users set photo = "$photo" where id = '$lo'") or die("error");

//header("Location: ksuc.php");
}


if($_error == '1')
{
$_error=0;
echo "<div class=redtext>There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";
}

if($_check == $_i)
{
$_check=0;
echo "<div class=redtext>Select a file first than click 'Upload File'</div>";
}
}
echo "</td></tr>";

?>






<table width=100% border=0 cellpadding=0 cellspacing=0>
<form enctype='multipart/form-data' action='' method='post' style=\"margin: 0px;\">
<tr><td><input type='hidden' name='MAX_FILE_SIZE' value='3000000'></td></tr>
<tr><td class=redtext>Photo Must Be 250px W by 250px H and in .JPG or .GIF format.</td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td class=bodytext>Choose your image:<br>
<?php
For($i=0; $i <= $_i-1;$i++)
{
echo "<input name='file" . $i . "' type='file'></td></tr>";
}
echo "<tr><td class=bodytext><input type=submit name=Submit value='Upload' style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; BACKGROUND-COLOR: #5E6456; COLOR: #ffffff;\"></td></tr>";
?>
</table>
0
<?php



$upload_dir = "d:/xampp/htdocs/images/"; //upload folder..chmod to 777
$_i = "1"; //number of files to upload at one time


if($_POST['Submit'] == 'Upload')
{

For($i=0; $i <= $_i-1; $i++)
{
$target_path = $upload_dir . basename($_FILES['file' . $i]['name']);
$target_path = str_replace (" ", "", $target_path);
$_file_name = basename($_FILES['file' . $i]['name']);
$_file_name = str_replace (" ", "", $_file_name);
$photo = $_file_name;

if(basename($_FILES['file' . $i]['name']) != '')
{
if(move_uploaded_file($_FILES['file' . $i]['tmp_name'], $target_path))
{
$_uploaded=1;
}
else
{
$_error=1;
}
}
else
{
$_check=$_check+1;
}
}

if($_uploaded == '1')
{
$_uploaded=0;
//$adID = $_GET['adID'];

//$Category = $_GET['Category'];


$link = mysql_connect("67.220.196.234","hassaninfo","9845098450") or die("Couldn't make connection.");
$db = mysql_select_db("hassaninfo", $link) or die("Couldn't select database");
$lo=$_GET['id'];
//echo $_file_name;
//echo $lo;
mysql_query("update users set photo = "$photo" where id = '$lo'") or die("error");

//header("Location: ksuc.php");
}


if($_error == '1')
{
$_error=0;
echo "<div class=redtext>There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";
}

if($_check == $_i)
{
$_check=0;
echo "<div class=redtext>Select a file first than click 'Upload File'</div>";
}
}
echo "</td></tr>";

?>






<table width=100% border=0 cellpadding=0 cellspacing=0>
<form enctype='multipart/form-data' action='' method='post' style=\"margin: 0px;\">
<tr><td><input type='hidden' name='MAX_FILE_SIZE' value='3000000'></td></tr>
<tr><td class=redtext>Photo Must Be 250px W by 250px H and in .JPG or .GIF format.</td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td class=bodytext>Choose your image:<br>
<?php
For($i=0; $i <= $_i-1;$i++)
{
echo "<input name='file" . $i . "' type='file'></td></tr>";
}
echo "<tr><td class=bodytext><input type=submit name=Submit value='Upload' style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; BACKGROUND-COLOR: #5E6456; COLOR: #ffffff;\"></td></tr>";
?>
</table>

It was showin this error


Parse error: syntax error, unexpected T_VARIABLE in D:\xampp\htdocs\image22.php on line 100 ie...in update query.....


pls help.......

0

This code to register ads from users....

<?php 

include 'd:/xampp/htdocs/onlinedbc.php';

$action = $_GET['act'];

if ($action == 1){
$Category = $_POST['Category'];
$Activity = $_POST['Activity'];
$NameOfCompany = $_POST['NameOfCompany'];
$Address = $_POST['Address'];
$Phone = $_POST['Phone'];
$Fax = $_POST['Fax'];
$Mobile = $_POST['Mobile'];
$emailId = $_POST['emailId'];
$Website = $_POST['Website'];

$duplicate = mysql_query("select count(*) as total from users where Category='$Category' and Activity='$Activity' and NameOfCompany='$NameOfCompany' and Address='$Address' and Phone='$Phone' and Fax='$Fax' and Mobile='$Mobile' and emailId='$emailId' and Website='$Website'") or die(mysql_error());
list($total) = mysql_fetch_row($duplicate);

if ($total > 0)
{
$err = "***ERROR: The Company details already exists. Please try again with different category.***";
header("Location: kregister.php?msg=$err");
exit();
}

$sql_insert = "INSERT into `users`
            (`Category`,`Activity`,`NameOfCompany`,`approved`,`Address`,`Phone`,`Fax`,`Mobile`,`emailId`,`Website`)
            VALUES
            ('$Category','$Activity','$NameOfCompany','0','$Address','$Phone','$Fax','$Mobile','$emailId','$Website')
            ";


$a = mysql_query($sql_insert,$link) or die("Insertion Failed:" . mysql_error());
$row=mysql_query("select max(id) from users") or die("error");


if( $a > 0){
 header("Location: image2.php");        
}


     } 
?>



from that php i extract id from database and send to next image2.php file...its code is

<?php


$upload_dir = "d:/xampp/htdocs/images/"; 
$_i = "1"; 


if($_POST['Submit'] == 'Upload')
{

For($i=0; $i <= $_i-1; $i++)
{
$target_path = $upload_dir . basename($_FILES['file' . $i]['name']);
$target_path = str_replace (" ", "", $target_path);
$_file_name = basename($_FILES['file' . $i]['name']);
$_file_name = str_replace (" ", "", $_file_name);

if(basename($_FILES['file' . $i]['name']) != '')
{
if(move_uploaded_file($_FILES['file' . $i]['tmp_name'], $target_path))
{
$_uploaded=1;
}
else
{
$_error=1;
}
}
else
{
$_check=$_check+1;
}
}

if($_uploaded == '1') 
{
$_uploaded=0;
$adID = $_GET['adID'];




$link = mysql_connect("67.220.196.234","hassaninfo","9845098450") or die("Couldn't make connection.");
$db = mysql_select_db("hassaninfo", $link) or die("Couldn't select database");
$lo=$_GET['id'];
//echo $_file_name;
//echo $lo;
 mysql_query("insert into users (photo) values ('".$_file_name."')") or die("error");

header("Location: ksuc.php");
}


if($_error == '1')
{
$_error=0;
echo "<div class=redtext>There was an error uploading some of the file(s), please try again! Maybe the file size is too large. Maximum file size is 3MB</div>";
}

if($_check == $_i)
{
$_check=0;
echo "<div class=redtext>Select a file first than click 'Upload File'</div>";
}
}
echo "</td></tr>";

?>






<table width=100% border=0 cellpadding=0 cellspacing=0>
<form enctype='multipart/form-data' action='' method='post' style=\"margin: 0px;\">
<tr><td><input type='hidden' name='MAX_FILE_SIZE' value='3000000'></td></tr>
<tr><td class=redtext>Photo Must Be 250px W by 250px H and in .JPG or .GIF format.</td></tr>
<tr><td>&nbsp;</td></tr>
<tr><td class=bodytext>Choose your image:<br>
<?php
For($i=0; $i <= $_i-1;$i++)
{
echo "<input name='file" . $i . "' type='file'></td></tr>";
}
echo "<tr><td class=bodytext><input type=submit name=Submit value='Upload' style=\"font-family: Verdana; font-size: 8pt; font-weight: bold; BACKGROUND-COLOR: #5E6456; COLOR: #ffffff;\"></td></tr>";
?>
</table>

i cant update its name in database...pls help....
if u have any idea r code pls send to me.....to store photo in some dir and its name in database...

is there any idea of insertin photo at the time of registration...

Edited by Nick Evan: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.