Jump to content

php, js, ajax help with uploading photo..


UnknownPlayer

Recommended Posts

I wonna to upload photo with js and ajax.. i can do inserting something in mysql, but i dont know how to do with files :/

 

Form:

	<form enctype="multipart/form-data" method="get">
	<center>
	  <label>Title: <input type="text" name="s_name" value="" style="width:250px" /></label>
	  <label>Image: <input type="file" name="s_image" style="width:250px" /></label>
	  <input class="button" type="submit" name="s_add" value="Add" style="width:100px" OnClick="save();" />
	</center>
</form>

 

This is js code:

function save() {
col = document.getElementById("new");
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		col.innerHTML = xmlhttp.responseText;
	}
}
xmlhttp.open("GET","sources/save.php?i dont know what to insert here,true);
xmlhttp.send();
}

 

this is save.php:

<?php
	$allowed_size = 204800;
	$name = $_GET['name'];
	$name = $_GET['image'];
	$date = time();
	if (save_img($up_imgfile, $up_imgname, $allowed_size)) {
		$query = "INSERT INTO table (name, image, date) VALUES ('{$name}', '{$image}', '$date')";
		$result = mysql_query($query, $connection);
		if ($result) {
			echo "<p class='warn-green'>$season_name has been successful added</p>";
		} else {
			echo "<p class='warn-red'>Error: $season_name is not added, try again.</p>";
		}
	}
}
?>

save_img() is php function to upload photo and make thumb..

 

How can i do this thing to do this function, but i need this:

$up_imgname = $_FILES['s_image']['name'];

$up_imgfile = $_FILES['s_image']['tmp_name'];

Becouse of that i cant do this, how can i get temp name, image name of uploaded file ?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.