2012-09-09 63 views
0

iam新增了php,我使用php的图片上传脚本来更新我的标志,每当用户选择图片文件时,现有图片文件应该被新的上传文件替换,并且应该在屏幕上更新对于这个iam使用这个脚本,但它没有做任何事情,我的意思是它也没有替换图像,也没有将新图像放入文件夹...... :(请帮我解决这个问题,我一直在这个因为几个月的问题..图片上传创建问题

这是setup.php

<?php include("../includes/config.php"); ?> 
<?php 
if ($_SESSION["isadmin"]) 
{ 

$con=mysql_connect($dbserver,$dbusername,$dbpassword); 
if (!$con) { die('Could not connect: ' . mysql_error()); } 

mysql_select_db($dbname, $con); 

$result = mysql_query("SELECT * FROM setup WHERE (id=".$_SESSION["id"].")"); 
while($row = mysql_fetch_array($result)) 
{ 
    $title = $row['title']; 
    $theme = $row['theme']; 
} 
mysql_close($con); 
?> 

<!DOCTYPE HTML> 
<html> 
<head> 
<title>Admdin Home</title> 
<link rel="StyleSheet" href="css/style.css" type="text/css" media="screen"> 
</head> 
<body> 
<?php include("includes/header.php"); ?> 
<?php include("includes/nav.php"); ?> 
<?php include("includes/aside.php"); ?> 
<div id="maincontent"> 

<div id="breadcrumbs"> 
    <a href="">Home</a> > 
    <a href="">Setup</a> > 
    Customization 
</div> 
<h2>Customize</h2> 
<?php 
if (isset($_GET["status"])) 
{ 
if($_GET["status"]==1) 
{ 
echo("<strong>Customization Done!</strong>"); 
} 
if($_GET["status"]==2) 
{ 
echo("<strong>Customization Error!!</strong>"); 
} 
} 

?> 
<form method="post" action="setup-action.php" enctype="multipart/form-data" > 
<label>Title Of Your Organization:</label> <input type="text" name="title" value="<? php  echo $title; ?>" /> <br /> <br /> 
<label>Select Theme</label> 
<select name="theme" value="<?php echo $theme; ?>"> 
<option value="Default">Default</option> 
<option value="Dark">Dark</option> 
<option value="White">White</option> 
</select> 
<br /> <br /> 
<label>Choose Your Logo Here</label><input type="file" name="file"/><br /> <br />  
<input type="submit" name="Upload" value="Upload" /> 
</form> 

</div> 

</body> 
<?php include("includes/footer.php"); ?> 
</html> 
<?php 
} 
else 
{ 
    header("Location: ".$fullpath."login/unauthorized.php"); 

} 
?> 

,这是设置-action.php的

<?php include("../includes/config.php");?> 
<?php 
if(isset($_FILES["file"])) 
{ 
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) 
&& ($_FILES["file"]["size"] < 1000000)) 
{ 
if ($_FILES["file"]["error"] > 0) 
    { 
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; 
    } 

    if (file_exists("../graphics/" . $_FILES["file"]["name"])) 
     { 
      echo $_FILES["file"]["name"] . " already exists. "; 
     } 
    else 
     { 
      move_uploaded_file($_FILES["file"]["name"], 
      "../graphics/" . $_FILES["file"]["name"]); 
      echo "Stored in: " . "../graphics/" . $_FILES["file"]["name"]; 
     } 
    } 
} 
else 
    { 
    echo "Invalid file"; 
    } 
?> 
<?php 
$title=$_POST["title"]; 
$theme=$_POST["theme"]; 
$con=mysql_connect($dbserver,$dbusername,$dbpassword); 
if (!$con) { die('Could not connect: ' . mysql_error()); } 

mysql_select_db($dbname, $con); 
$result=mysql_query("SELECT * FROM setup WHERE id=".$_SESSION['id']); 
$num_rows = mysql_num_rows($result); 
if ($num_rows > 0) 
{ 
{ 
mysql_query("UPDATE setup SET title='".$title."' , theme='".$theme."'WHERE id=".$_SESSION['id']); 
header("Location:setup.php?status=1"); 
} 
} 
else { 
header("Location:setup.php?status=2"); 
} 
mysql_close($con); 
?> 
+0

你得到任何错误? –

回答

0

看到这个URL

http://www.tizag.com/phpT/fileupload.php

试试这个: -

<form enctype="multipart/form-data" action="uploader.php" method="POST"> 
<input type="hidden" name="MAX_FILE_SIZE" value="100000" /> 
Choose a file to upload: <input name="uploadedfile" type="file" /><br /> 
<input type="submit" value="Upload File" /> 
</form> 

uploder.php

$target_path = "uploads/"; 

$target_path = $target_path . basename($_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 
    echo "The file ". basename($_FILES['uploadedfile']['name']). 
    " has been uploaded"; 
} else{ 
    echo "There was an error uploading the file, please try again!"; 
} 
+0

感谢您的帮助,我想放置此文件的文件夹的名称是图形...所以我应该使用 $ target_path =“graphics /”; ?? ,我应该离开伊什么东西,因为它是。或者我应该更改文件n文件夹的名称? plz帮助.. –

+0

谢谢你这么多的代码工作atleast :)现在它的保存/上传图形文件夹中的文件,但我应该怎么做,以取代现有的图像与新上传的图像? thankx提前.thankyou这么多你的帮助:)) –

0
 STEP1: Create file upload.php 
    ############### Code 

    `<table width="500" border="0" align="center" cellpadding="0" cellspacing="1"   bgcolor="#CCCCCC"> 
     <tr> 
    <form action="upload_ac.php" method="post" enctype="multipart/form-data"  name="form1" id="form1"> 
    <td> 
    <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF"> 
    <tr> 
<td><strong>Single File Upload </strong></td> 
</tr> 
<tr> 
<td>Select file 
<input name="ufile" type="file" id="ufile" size="50" /></td> 
</tr> 
<tr> 
<td align="center"><input type="submit" name="Submit" value="Upload" /></td> 
</tr> 
</table> 
</td> 
</form> 
</tr> 
</table> 
` 
STEP2: Create file upload_ac.php 
    ############### Code 



    <?php 
    //set where you want to store files 
    //in this example we keep file in folder upload 
    //$HTTP_POST_FILES['ufile']['name']; = upload file name 
    //for example upload file name cartoon.gif . $path will be upload/cartoon.gif 

    $path= "upload/".$HTTP_POST_FILES['ufile']['name']; 
    if($ufile !=none) 
{ 
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) 
{ 
echo "Successful<BR/>"; 

//$HTTP_POST_FILES['ufile']['name'] = file name 
//$HTTP_POST_FILES['ufile']['size'] = file size 
//$HTTP_POST_FILES['ufile']['type'] = type of file 

echo "File Name :".$HTTP_POST_FILES['ufile']['name']."<BR/>"; 
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; 
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; 
echo "<img src=\"$path\" width=\"150\" height=\"150\">"; 
} 
else 
{ 
echo "Error"; 
} 
} 
?>