This tutorial http://www.blocsoft.com/blog/imageshack.asp shows a great way to upload to imageshack and get a image url back although its for ASP and I need it in PHP.
Any ideas if and how this could be done?
Thanks heaps.
I just rewrote the asp to php, no clue if it works haven't tested it, but if the asp does work then the php should also.
index.php
<html>
<head>
<title>AJAX image upload</title>
</head>
<body>
<form action="http://imageshack.us/redirect_api.php" target="AXframe" method="post" enctype="multipart/form-data">
<input type="file" name="media"/>
<input type="hidden" name="key" value="YOUR_DEVELOPER_KEY">
<input type="hidden" name="error_url" value="http://example.com/error.php">
<input type="hidden" name="success_url" value="http://example.com/success.php?one=%y&two=%u&three=%s&four=%b&five=%i">
<input type="submit"/>
</form>
<iframe style="visibility:hidden" id="AXframe" name="AXframe"></iframe>
<div id="link"></div>
<div id="yfrog"></div>
<div id="image"></div>
</body>
</html>
success.php
<?php
$str1 = $_GET["one"];
$str2 = $_GET["two"];
$str3 = $_GET["three"];
$str4 = $_GET["four"];
$str5 = $_GET["five"];
?>
<script type="text/javascript">
parent.document.getElementById('yfrog').innerHTML = '<?php echo($str1); ?>';
parent.document.getElementById('link').innerHTML = '<?php echo($str2); ?>';
parent.document.getElementById('image').innerHTML = '<img src="http://img<?php echo($str3); ?>.imageshack.us/img<?php echo($str3); ?>/<?php echo($str4); ?>/<?php echo($str5); ?>">';
</script>
error.php
<script type="text/javascript">
alert("There was an error uploading the file.");
</script>
Related
I have this code (it's an include), but the thing is that when I send the form the $_POST data is not being sent.
Im checking for $_POST data like this
if(isset($_POST['ft_upload']) && $_POST['ft_upload'] == 1){
//$usuario -> uploadFirstTime2($db);
echo "ok";
}
and the code for the form is
<div class="ft_userImage" style="background: url(<?php echo $usuario -> getProfileImage(); ?>);"></div>
<p class="ft_step2_continue"><?=$TEXT_BUTTONS['continue'];?></p>
<form action="" method="POST" class="ft_step2_form_upload">
<input type="hidden" name="ft_upload" value="1" />
</form>
<script>
$("p.ft_step2_continue").click(function(){
$(".ft_step2_form_upload").submit();
});
</script>
check.php
<?php
if(isset($_POST['ft_upload']) && $_POST['ft_upload'] == 1) {
echo "ok";
}
?>
index.html
<!DOCTYPE html>
<html>
<head>
<title>form</title>
</head>
<body>
<form action="check.php" method="POST" class="ft_step2_form_upload">
<input type="hidden" name="ft_upload" value="1" />
</form>
<button id="ft_step2_continue">SEND</button>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$("#ft_step2_continue").click(function(){
$(".ft_step2_form_upload").submit();
});
</script>
</body>
</html>
it works fine.
i think, you just forgot action="check.php" in your form tag.
Here check this:
<?php var_dump($_POST); ?>
<html>
<head>
<title></title>
</head>
<body>
<form action="" method="POST" class="ft_step2_form_upload">
<input type="hidden" name="ft_upload" value="1" />
</form>
<script src="https://code.jquery.com/jquery-3.1.1.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script>
$("p.ft_step2_continue").click(function(){
$(".ft_step2_form_upload").submit();
});
</script>
</body>
</html>
Ok so i did this. Saved it in a php file. And then triggered the submit and it outputs:
array(1) { ["ft_upload"]=> string(1) "1" }
Your php code should be in the same file where the form html is written because your action attribute is empty.
You need to specify the action attribute.
<form action="check.php" method="POST" class="ft_step2_form_upload">
I think you want transfer a file to server??? if yes:
<form method="POST" action="this-file-name.php" enctype="multiform/form-data">
Your Photo:
<input type="file" name="filet" required="required">
<input type="submit" value="Send Photo">
</form>
<?php
if(isset($_FILES['filet'])) {
$dir = './my_dir_name/';
$file_name = $_FILES['filet']['name'];
$doit = #move_uploaded_file($_FILES['filet']['tmp_name'],$dir.$file_name);
if($doit) {
echo 'File '.$file_name.' uploaded';
}
}
?>
My HTML:
<form action="test.php" method="get">
<input type="text" name="text" />
</form>
My PHP:
<html>
<head>
<title>Result</title>
</head>
<body style="background:aqua;">
<?php
$text = $_GET["text"];
$text_html = htmlspecialchars($text);
echo "<h1>Hi, {$text_html}</h1>";
?>
</body>
I want to transport and show data input from type="text" fields in my HTML form, into my PHP file, but the result is as per below:
Hi, {$text_html}"; ?>
Why is the extra code showing?
This is my Source Code.
Assuming you use something (like js) to submit your form.
When you try to output a variable you should use concat of strings.
// this will print the variable name, not is content
echo "<h1>Hi, {$text_html}</h1>";
// Using '.' you can concat strings, so:
echo "<h1>Hi".$text_html."</h1>";
In this way you tell the script that you want the value of $text_html instead of print the string "$text_html"
Hello You need to change in your form code you have to add submit button just. all other code is working fine. Just change your form code with below code.
<form action="test.php" method="get">
<input type="text" name="text" />
<input type="submit" name="submit" value="submit" />
</form>
Because you need to transform data from one page to other page either via form submit or you can use Session or Cookie. but currently in your case you just need to add submit button your code work
You will need a submit button. After the submit button is trigerd the if condition will be set to true and the code will execute.
<html>
<head>
<title>Result</title>
</head>
<body style="background:aqua;">
<form action="test.php" method="get">
<input type="text" name="text" />
<input type="submit" name="submit" value="submit" />
</form>
<?php
if(isset($_GET["submit"])){
$text = $_GET["text"];
$text_html = htmlspecialchars($text);
echo "<h1>Hi".$text_html."</h1>";
}
?>
</body>
<html>
<head>
<title>Result</title>
</head>
<body style="background:aqua;">
<form action="test.php" method="get">
<input type="text" name="text" />
<input type="submit" name="submit" value="submit" /> // add submit button
</form> ////html page
on php page
<?php
if(isset($_GET["submit"])){
$text = $_GET["text"];
$text_html = htmlspecialchars($text);
echo "<h1>Hi".$text_html."</h1>";
}
?>
<html>
<head>
<title>Result</title>
<meta charset="UTF-8">
</head>
<body style="background:aqua;">
<?php
if(isset($_GET["submit"])){
$text = $_GET["text"];
$text_html = htmlspecialchars($text);
echo "<div>Hi,".$text_html."<div>";
}
?>
</body>
I'm brand new to this and trying to scab together two different ideas. Each of them work individually, but I'm trying to integrate them.
I am able to upload and image (which creates a list itme with an href="javascript:void(0).
I can allow user input to assign a url to an existing text link.
what I'm trying to do is target the dynamically created list item in the upload.php page and change the href="javascript:void(0) to the user specified variable from index.php
index.php code
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>image upload</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#images').on('change',function(){
$('#multiple_upload_form').ajaxForm({
target:'#images_preview',
beforeSubmit:function(e){
$('.uploading').show();
},
success:function(e){
$('.uploading').hide();
},
error:function(e){
}
}).submit();
});
});
</script>
</head>
<body>
<div style="margin-top:50px;">
<div class="upload_div" >
<form name="multiple_upload_form" id="multiple_upload_form" enctype="multipart/form-data" action="upload.php">
<input type="hidden" name="image_form_submit" value="1"/>
<label>Choose Image</label>
<input type="file" name="images[]" id="images" multiple >
<div class="uploading none">
<label> </label>
<img src="uploading.gif"/>
</div>
</form>
</div>
<div class="gallery" id="images_preview">
</div>
</div>
<div class="form_div" id="url_input">
<form id="form1">
URL - example http://www.yourdomain.com: <input name="name" type="text" size="20">
</form>
<button onclick="outputname()">Submit</button>
<script>
function outputname() {
var x,y,name,a,b,answer;
x=document.getElementById("form1") ;
y=x.elements["name"].value;
document.getElementById("upload.php#web").setAttribute("href",y);
}
</script>
<p id="demo">
<a id="link">this is a link</a>
</p>
</div>
</body>
</html>
upload.php code
<?php
if($_POST['image_form_submit'] == 1)
{
$images_arr = array();
foreach($_FILES['images']['name'] as $key=>$val){
$image_name = $_FILES['images']['name'][$key];
$tmp_name = $_FILES['images']['tmp_name'][$key];
$size = $_FILES['images']['size'][$key];
$type = $_FILES['images']['type'][$key];
$error = $_FILES['images']['error'][$key];
############ Remove comments if you want to upload and stored images into the "uploads/" folder #############
/*$target_dir = "uploads/";
$target_file = $target_dir.$_FILES['images']['name'][$key];
if(move_uploaded_file($_FILES['images']['tmp_name'][$key],$target_file)){
$images_arr[] = $target_file;
}*/
//display images without stored
$extra_info = getimagesize($_FILES['images']['tmp_name'][$key]);
$images_arr[] = "data:" . $extra_info["mime"] . ";base64," . base64_encode(file_get_contents($_FILES['images']['tmp_name'][$key]));
}
//Generate images view
if(!empty($images_arr)){ $count=0;
foreach($images_arr as $image_src){ $count++?>
<ul class="reorder_ul reorder-photos-list">
<li id="image_li_<?php echo $count; ?>" class="ui-sortable-handle">
<img src="<?php echo $image_src; ?>" alt="">
</li>
</ul>
<?php }
}
}
?>
Like I said, I'm brand new to this and there may be a far more elegant solution, but I've gotten this far from just hunting and pecking... thanks in advance for any help.
I made this simple chat site for my website but I don't know how to make it auto refresh every time a message has been sent.
Site that sends and prints out all messages:
<form action="messages.php" method="POST">
<input name="chat_box" /><br>
<input type="submit" value="Send" />
</form>
<?php
include "messages.txt";
?>
Site that sends text input to a text file:
<?php
$messages = $_POST["chat_box"];
$handler=fopen("messages.txt", 'a');
fwrite($handler,$_SERVER["REMOTE_ADDR"].":".$messages."<br>");
fclose($handler);
header("Location: chat_box.php");
?>
Can anyone help me?
Try this code :
This is a messages.php :
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
<form action="messages.php" method="POST">
<input name="chat_box" /><br>
<input type="submit" value="Send" />
</form>
<?php
include "messages.txt"; //Uncomment this to check the autorefresh
echo "Auto refresh in 10 second!";
$messages = $_POST["chat_box"];
$handler=fopen("messages.txt", 'a');
fwrite($handler,$_SERVER["REMOTE_ADDR"].":".$messages."<br>");
fclose($handler);
?>
</body>
</html>
Hope this help you out... :)
If you mean to get new messages, your best bet is probably to re-load the text file every 10 seconds. to do so replace the php in the bottom of your 1st code set with this:
<div id="messages"></div>
<script type="text/javascript">
$(document).ready(function() {
function functionToLoadFile(){
jQuery.get('messages.txt', function(data) {
$("#messages").html(data)
});
}
setInterval(functionToLoadFile, 10000);
});
</script>
I am trying to implement a very basic AJAX upload progress bar using the PECL uploadprogress extension. I have found this sample code which works across all browsers: http://svn.php.net/viewvc/pecl/uploadprogress/trunk/examples/. It uses iframes to write the updates to. I would like to get the updates and do some jquery to build a progress bar. Here is my code (I know I did not write in code to account for when the upload ends) client.php:
<?php
$id = md5(microtime() . rand());
?>
<!DOCTYPE html>
<html>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
function getProgress(){
$.get("progress.php", {"ID":'<?php echo $id ?>'}, function(data){
console.log(data);
});
window.setTimeout(getProgress(), 5000);
}
</script>
<body>
<form onsubmit="getProgress()" target="_self" enctype="multipart/form-data" method="post">
<input type="hidden" name="UPLOAD_IDENTIFIER" value="<?php echo $id;?>" />
<label>Select File:</label>
<input type="file" name="file" />
<br/>
<label>Select File:</label>
<input type="file" name="file2" />
<br/>
<label>Upload File:</label>
<input id="submitButton" type="submit" value="Upload File" />
</form>
</body>
</html>
And progress.php:
<?php
if (function_exists("uploadprogress_get_info")) {
$info = uploadprogress_get_info($_GET['ID']);
} else {
$info = false;
}
$progress = ($info['bytes_uploaded']/$info['bytes_total'])*100;
echo $progress;
I error out and all that prints is 0's. Any ideas?
Try replacing
$progress = ($info['bytes_uploaded']/$info['bytes_total'])*100;
with
$progress = ($info['bytes_uploaded']*100)/$info['bytes_total'];
Both $info['bytes_uploaded'] and $info['bytes_total'] are integers, so division is not a float but is rounded down to a integer.