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
my objective is this that when i uplod a file it should be desply on same page with ajax uplod after when i refresh page this should be not remains longer and on clicking other image its replase previous image
plz help
how i can do this the code i have found is here
--------------------------------------index.php---------------------------------------------------- -
<html>
-
<head>
-
<title>Asynchronous image file upload without AJAX</title>
-
<style>
-
iframe {
-
border-width: 0px;
-
height: 60px;
-
width: 400px;
-
}
-
iframe.hidden {
-
visibility: hidden;
-
width:0px;
-
height:0px;
-
}
-
-
#main {
-
overflow: hidden;
-
margin: auto;
-
width: 720px;
-
height: 500px;
-
background-color: white;
-
}
-
-
#images {
-
width: 390px;
-
margin: 20px;
-
}
-
-
#images div {
-
margin: 10px;
-
width: 100px;
-
height: 100px;
-
float: left;
-
overflow: hidden;
-
}
-
-
#images div:hover {
-
border-color: #529EBD;
-
}
-
-
#images img.load {
-
margin: 36px;
-
}
-
</style>
-
</html>
-
<body><center>
-
<div id="main">
-
<div id="iframe_container">
-
<iframe src="upload.php" frameborder="0"></iframe>
-
</div>
-
<div id="images_container">
-
</div>
-
</div>
-
</center></body>
-
</html>
-
-
-----------------------------------------upload.php------------------------------------------------------ -
<?php
-
error_reporting(E_ALL);
-
if (isset($_FILES['image'])) {
-
$ftmp = $_FILES['image']['tmp_name'];
-
$oname = $_FILES['image']['name'];
-
$fname = "upload/".$_FILES['image']['name'];
-
if(move_uploaded_file($ftmp, $fname)){
-
?>
-
<html><head><script>
-
var par = window.parent.document;
-
var images = par.getElementById('images_container');
-
var imgdiv = images.getElementsByTagName('div')[<?=(int)$_POST['imgnum']?>];
-
var image = imgdiv.getElementsByTagName('img')[0];
-
imgdiv.removeChild(image);
-
var image_new = par.createElement('img');
-
image_new.src = 'resize.php?pic=<?=$oname?>';
-
image_new.className = 'loaded';
-
imgdiv.appendChild(image_new);
-
</script></head>
-
</html>
-
<?php
-
exit();
-
}
-
}
-
?><html><head>
-
<script language="javascript">
-
function upload(){
-
var par = window.parent.document;
-
-
// hide old iframe
-
var iframes = par.getElementsByTagName('iframe');
-
var iframe = iframes[iframes.length - 1];
-
iframe.className = 'hidden';
-
-
// create new iframe
-
var new_iframe = par.createElement('iframe');
-
new_iframe.src = 'upload.php';
-
new_iframe.frameBorder = '0';
-
par.getElementById('iframe_container').appendChild (new_iframe);
-
-
// add image progress
-
var images = par.getElementById('images_container');
-
var new_div = par.createElement('div');
-
var new_img = par.createElement('img');
-
new_img.src = 'indicator.gif';
-
new_img.className = 'load';
-
new_div.appendChild(new_img);
-
images.appendChild(new_div);
-
-
// send
-
var imgnum = images.getElementsByTagName('div').length - 1;
-
document.iform.imgnum.value = imgnum;
-
setTimeout(document.iform.submit(),5000);
-
}
-
</script>
-
<style>
-
#file {
-
width: 350px;
-
}
-
</style>
-
<head><body><center>
-
<form name="iform" action="" method="post" enctype="multipart/form-data">
-
<input id="file" type="file" name="image" onChange="upload()" />
-
<input type="hidden" name="imgnum" />
-
</form>
-
</center></html>
-
----------------------------------------resize.php----------------------------------------------- -
<?php
-
if($_GET['pic']){
-
$img = new img('upload/'.$_GET['pic']);
-
$img->resize();
-
$img->show();
-
}
-
-
class img {
-
-
var $image = '';
-
var $temp = '';
-
-
function img($sourceFile){
-
if(file_exists($sourceFile)){
-
$this->image = ImageCreateFromJPEG($sourceFile);
-
} else {
-
$this->errorHandler();
-
}
-
return;
-
}
-
-
function resize($width = 100, $height = 100, $aspectradio = true){
-
$o_wd = imagesx($this->image);
-
$o_ht = imagesy($this->image);
-
if(isset($aspectradio)&&$aspectradio) {
-
$w = round($o_wd * $height / $o_ht);
-
$h = round($o_ht * $width / $o_wd);
-
if(($height-$h)<($width-$w)){
-
$width =& $w;
-
} else {
-
$height =& $h;
-
}
-
}
-
$this->temp = imageCreateTrueColor($width,$height);
-
imageCopyResampled($this->temp, $this->image,
-
0, 0, 0, 0, $width, $height, $o_wd, $o_ht);
-
$this->sync();
-
return;
-
}
-
-
function sync(){
-
$this->image =& $this->temp;
-
unset($this->temp);
-
$this->temp = '';
-
return;
-
}
-
-
function show(){
-
$this->_sendHeader();
-
ImageJPEG($this->image);
-
return;
-
}
-
-
function _sendHeader(){
-
header('Content-Type: image/jpeg');
-
}
-
-
function errorHandler(){
-
echo "error";
-
exit();
-
}
-
-
function store($file){
-
ImageJPEG($this->image,$file);
-
return;
-
}
-
-
function watermark($pngImage, $left = 0, $top = 0){
-
ImageAlphaBlending($this->image, true);
-
$layer = ImageCreateFromPNG($pngImage);
-
$logoW = ImageSX($layer);
-
$logoH = ImageSY($layer);
-
ImageCopy($this->image, $layer, $left, $top, 0, 0, $logoW, $logoH);
-
}
-
}
-
?>
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------
i think resize.php is not necessary for my purpose
1 3952 pbmods 5,821
Recognized Expert Expert
Heya, Sandeep. Welcome to TSDN!
Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.
Changed thread title to better describe the problem (did you know that threads whose titles do not follow the Posting Guidelines actually get FEWER responses?).
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Willoughby Bridge |
last post by:
I am having trouble with a file upload script. Have tried a lot of
different methods and the problem boils down to the $_FILES variable not
being picked up. Below is a simple example of Upload2.php having a blank
value for $_FILES. I am using PHP through my web host
yahoo. I'd appreciate any thoughts on how to resolve this this.
<form enctype="multipart/form-data" method="post" action="upload2.php">
Send this file: <input...
|
by: Chuck |
last post by:
Hi, can anyone provide or point me in the direction of a simple python
file upload script? I've got the HTML form part going but simply
putting the file in a directory on the server is what I'm looking for.
Any help would be greatly appreciated.
Thanks,
Chuck
|
by: fatjoez |
last post by:
Hey there.
I've been trying to modify my file upload script so that it handles 10 files instead of one.
i was thinking the most straightforward way would be to add a FOR LOOP? placed strategically somewhere like just before the my variables get declared???
the POST input name is "fileup" so maybe i could call them fileup1, fileup2 etc.
This is the upld.pl script itself.
|
by: markus.rietzler |
last post by:
i want to do (multiple) file upload(s) and display a progress bar.
with firefox and safari it is no problem at all. only IE makes some
problems.
my script is based on ajax-uploader, which can be found at
www.srmiles.com/freestuff/ajax_file_uploader/ . you can do multiple
file uploads. each upload will have it's own "form"-tag, so that each
file is uploaded for its own. could be a good solution if there are
"big" uploads.
|
by: wasif |
last post by:
I am trying to upload file using ajax and php but having some problems. it always says that there was a problem and file is not uploaded. here is the code
form and ajax code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled...
| |
by: pritisolank |
last post by:
Hello everyone,
I am trying to do ajax file upload i am half way and now i don't find any way to reach :-(
can someone tell me how to do a file upload in ajax+PHP.
regards,
priti
|
by: Ken1 |
last post by:
Hello,
Does anyone know of an easy to implement ajax upload script for php
which also has a progress bar. If possible I'd like it to be able to
remove already uploaded files and do minor manipulations...
Thanks.
|
by: dreamznatcher |
last post by:
Hello,
I found a script here: http://www.webtoolkit.info/ajax-file-upload.html
which supposedly allows you to upload files using AJAX (I'm not an
expert). The site claims it's the best way to upload files out there,
and the file size is only 1 kb.
I couldn't get it to work for me. I downloaded the files to my
computer, and opened the index file with my browser. It doesn't work
(the demo on their site does); IE doesn't show any error...
|
by: ramg80 |
last post by:
Hi,
I m using ajax to upload a file. I m using servlets (MultipartFormDataRequest) to upload the file.
My script contains the form data and the file. I m able to get the values of the form data.
Can any one please tell me what i m missing here.
var boundaryString = 'AaB03x';
var boundary = boundaryString;
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |