0

希望一切都会好起来...我想做一些事情,比如我有一个 php 图片上传器,这里是上传器的链接:http: //alitechn.w08.wh-2.com/undo_testing/uploader/upload.php

因此,当有人打开链接以使图像显示为空白时,我想在静态 html 中添加一些图像,但通常当有人上传图像时,新图像会替换静态图像..!

这是upload.php文件的完整代码:

<?php
    $fulltarget = '';

@$submit=$_POST['sub'];
if(isset($submit))
{
$name=$_FILES['img']['name'];
$type=$_FILES['img']['type'];

$size=($_FILES['img']['size'])/1024;

$ext=end(explode('.',$name));
if (($ext == "gif")
|| ($ext == "jpeg")
|| ($ext == "jpg")
|| ($ext =="png")
&& ($size > 30))
{


############################## File Renaming ###################################################

$newname=uniqid();
//$ext=end(explode('.',$name));
$fullname=$newname.".".$ext;
$target="pics/";

$fulltarget="http://alitechn.w08.wh-2.com/undo_testing/uploader/{$target}{$fullname}";
if($should_display_static){
$fulltarget="http://www.ipic-uk.com/images/homepage/upload_your_photo.png";


}
if(move_uploaded_file($_FILES['img']['tmp_name'],$fulltarget))
{
echo "Success";
}
else
{
echo "Failed";
}
############################## File Renaming end ###################################################
}
else{
echo "not successful";
}
}
?>
    <div>
 <div id="a1">
 <form name="frm" method="post" enctype="multipart/form-data">
 <div class="upload" style="width: 157px; height: 57px">  
  <input type="file" class="dark-button" name="img" style="width: 88px; height: 29px" /></div>
 <input type="submit" class="auto-style1" value="Store" style="width: 149px; height: 36px" /> 
<style type="text/css">
.styled-button-12 {
background:#5B74A8;
background:-moz-linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#5B74A8),color-stop(100%,#5B74A8));
background:-webkit-linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
background:-o-linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
background:-ms-linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
background:linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#5B74A8',endColorstr='#5B74A8',GradientType=0);
padding:2px 6px;
color:#fff;
font-family:'Helvetica',sans-serif;
font-size:11px;
border-radius:0;
-moz-border-radius:0;
-webkit-border-radius:0;
border:1px solid #1A356E
}
.auto-style1 {
background: #5B74A8;
background: -moz-linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#5B74A8),color-stop(100%,#5B74A8));
background: -webkit-linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
background: -o-linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
background: -ms-linear-gradient(top,#5B74A8 0%,#5B74A8 100%);
background: #5B74A8;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#5B74A8',endColorstr='#5B74A8',GradientType=0);
padding: 2px 6px;
color: #fff;
font-family: 'Helvetica',sans-serif;
font-size: 11px;
border-radius: 0;
-moz-border-radius: 0;
-webkit-border-radius: 0;
border: 1px solid #1A356E;
margin-left: 162;
}
</style>
</form>
</div>
<div id="a2">

<?php echo "

<html>
<head>
<title>Aviary Photo Editer</title>
<!-- Load Feather code -->
<script type='text/javascript' src='http://feather.aviary.com/js/feather.js'></script>
<!-- Instantiate Feather -->
<script type='text/javascript'>
var featherEditor = new Aviary.Feather({
apiKey: 'ceegvx4siylhayrr',
apiVersion: 3,
theme: 'dark', // Check out our new 'light' and 'dark' themes!
tools: 'enhance,frames,crop,orientation,brightness,saturation,sharpness,draw,redeye,blemish,effects,stickers,resize,focus,contrast,warmth,colorsplash,text,whiten',
appendTo: '',
onSave: function(imageID, newURL) {
    var img = document.getElementById(imageID);
    img.src = newURL;
    var object = document.getElementsByName('cardlink');
    object.item(0).value=newURL;
    input.value= newURL;    

},
onError: function(errorObj) {
    alert(errorObj.message);
}
});
function launchEditor(id, src) {
featherEditor.launch({
    image: id,
    url: src
 });
return false;
}
 </script>
</head>

<body>

<div id='injection_site'></div>

<img id='image1' src='".$fulltarget."' width='300px' height='400px'/>

<p><input type='image' src='http://images.aviary.com/images/edit-photo.png' value='Edit photo' onclick=\"return launchEditor('image1','".$fulltarget."');\" /></p>";



?>

<div onSave="function(imageID, newURL);">
<form action="contact-form/index.php" method="post">
<div><label for="cardlink">Card Image Link:<input type="text" name="cardlink" id="cardlink" style="width: 323px; height: 25px" /></label></div>

                    <a href="#" onclick="$(this).closest('form').submit()"  class="dark-button add-to-cart">Submit</a>



                </input>    </form>
 </div>
</div>
4

1 回答 1

0

将 $fulltarget 更改为要显示的图像的绝对路径。然后,每当您确定要显示静态图像时,将 $fulltarget 更改为指向静态图像。

$fulltarget="http://alitechn.w08.wh-2.com/undo_testing/uploader/{$target}{$fullname}";

然后检查是否要显示静态图像(您没有指定条件)

if($should_display_static)[
    $fulltarget="http://path/to/static/image.jpg";
}

然后显然将您的 img 代码更改为:

<img id='image1' src='".$fulltarget."' width='300px' height='400px'/>
于 2013-09-21T18:25:42.797 回答