I am trying to create live editing of a server file on an other server. I managed to download and save it as tmpfile(). After editing the file I want to save the changes. my HTML code looks like this:
<body>
<form method='post'>
<textarea name='text' class='textfield' id='textf'>$text</textarea>
<input type='submit'>
<input type='hidden' name='valuea' value='$server'>
<input type='hidden' name='valueb' value='$user'>
<input type='hidden' name='valuec' value='$safelocation'>
<input type='file' name='temp' value='$tempfile'>
</form>
</body>
I am not able to send the $tempfile again to my php code. I tried to cast the POST value as resource but that will not be a/the same temp file. $file = (resource)($_POST['temp']);
How could I manage to send the same file I editied to the same php script and use it again?
Related
I want to send an already existing image stored in the $_FILES['the_file']. The $_FILES['the_file'] is from the page "img_upload.php" for uploading that image, then it is sent to the "form.php" page where the rest of the form is, and then sent to the processing page named "add_product.php"
My problem is that I want to send the $_FILES['the_file'] from the form on "form.php" page to "add_product.php" page (with the rest of the form from "form.php"). How can I do that?
Here is my code:
// img_upload.php
<form action="form.php" method="post" enctype="multipart/form-data">
<input type='file' name='the_file' class='image-selector'>
<button type="submit">Insert the picture</button>
</form>
// form.php
<?php
$file = $_FILES['the_file'];
$fileName = $_FILES['the_file']['name'];
$fileSize = $_FILES['the_file']['size'];
$fileTmpName = $_FILES['the_file']['tmp_name'];
$fileType = $_FILES['the_file']['type'];
?>
<p>Picture name: <?php echo $fileName; ?></p>
<form action="../Includes/add_product.php" method="post" enctype="multipart/form-data">
<?php
echo "<input type='hidden' name='file' value=".$file.">";
?>
<input type="text" name="price" placeholder="Name the price">
<input type="text" name="sent_from" placeholder="Sent from">
<input type="text" name="category" placeholder="Select the category">
<button type="submit">Insert the product</button>
</form>
If you want to include it in a hidden input then you'll need to encode it as a string. The usual way to do that is to base64 encode it.
This question covers how to do that.
When you insert the string into the document, do make sure you make use of htmlspecialchars so you don't expose yourself to XSS attacks.
That approach involves sending the file to the server, then sending it (in a less compressed form) back to the browser, then sending it back to the server again.
This is not bandwidth efficient!
Usually the approach for this would be the same the file on the server and then send an id (e.g. the file name) back to the client (and have some logic for cleaning up old files left over from the user abandoning the process part way through).
I would like my user after register an account on my website and have their own unique QR code. The QR code will only contain the member serial number and for us to scan whether the user is truly our member. So may I ask everyone how am I going to achieve that and with what? My entire website is using PHP to write.
This is the code to generate qr code in php
<body onload="loadGraph()">
<form action='https://chart.googleapis.com/chart' method='POST' id='post_form' onsubmit="this.action = 'https://chart.googleapis.com/chart?chid=' + (new Date()).getMilliseconds();
return true;"> <input type='hidden' name='cht' value='qr' />
<input type='hidden' name='cht' value='qr' />
<input type='hidden' name='chs' value='300x300' />
<input type='hidden' name='chl' value='This is your QR code. You need to pass the users serial number here '/>
<input type='submit' value="Download your Qr code Here" />
</form>
change the code accordingly for your requirement.
We are trying to get some HTML source code using an API written in PHP. The PHP code uses json_encode to encode the response and then echoes it. The response we receive is similar to this.
{"status":true,"message":"Form fetched.","html":"
<!DOCTYPE html>\n\n
<html>\n\n
<head>\n\n<\/head>\n\n
<body onload=\"document.form.submit()\">\n\n\t
<div>\n\t\t\t
<img src='https:\/\/www.example.com\/resource\/images\/loader.gif' width='300px' height='300px'\/>\n\t\t\tPlease wait while we redirect you...\n\t<\/div>\n\n\t
<form name='form' method='POST' action='https:\/\/test.test.com\/_payment'>\n\t\t
<input type='hidden' name='key' value='randomFFx'>\n\t\t
<input type='hidden' name='txnid' value='YHOOCH31DG90HeQpc8h7'>\n\t\t
<input type='hidden' name='productinfo' value='Adding to user.'>\n\t\t
<input type='hidden' name='amount' value='100'>\n\t\t
<input type='hidden' name='firstname' value='test'>\n\t\t
<input type='hidden' name='lastname' value='test'>\n\t\t
<input type='hidden' name='email' value='support#example.com'>\n\t\t
<\/form>\n<\/body>\n<\/html>"}
How do I get a proper HTML code without \n\t which I can show in the webview. Currently due to these, the form isn't getting submitted automatically. We have tried replacing \n, \t, \ with , but is there a better method to retrieve the HTML code. Thanks in advance for all your help and suggestions.
This question already has answers here:
How to get the file path in html <input type="file"> in PHP?
(3 answers)
Closed 9 years ago.
i m trying to update images using GET method
user_form.php
<form action='upload.php' method='get'>
<input type='file' name='user_img' />
<input type='text' name='username' />
<input type='submit' name='update' value='update'>
</form>
upload.php
if(isset($_GET['update']))
{
echo 'username: '.$_GET['username'];
echo 'file name: '.$_FILES['user_img']['tmp_name'];
}
i m getting correct value for username, however, blank value for filename.
can anyone please let me know if we can use $_FILES variable for GET method? if yes then please point out where m i going wrong in the above sample code. thank you.
You cannot upload files using a GET HTTP request. Files are sent in the HTTP body, which requires a POST or PUT request.
You need to do:
<form action="someaction.php" method="post" enctype="multipart/form-data">
Add this to your form tag:
enctype = multipart/form-data
You should send your form by post method and specify that this form will have a file
<form action='' method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<input type='file' name='user_img' />
<input type='text' name='username' />
<input type='submit' name='update' value='update'>
</form>
It is also preferable for reasons of security and performance to indicate the maximum size of files to be sent.
You need to add enctype = multipart/form-data in a form if you want to upload /use files.
I succeeded in storing all the image information as a blob in MySQL via the form tag and php.
Now I'm trying to make an update form using PHP5. However, I'm not sure how to take all the information back from MySQL and show it to users that an image has been already posted.. like any other typical forum / blog pages that shows previously added files.
Any suggestions..? Thank you.
<form method="post" enctype="multipart/form-data" action="UpdateNewsPHP.php">
Title : <input name='TitleFieldToAdd' type='text' size='20' value='<?php echo $row["Title"] ?>'/> <br/>
Thread : <textarea name='ThreadFieldToAdd' cols="40" rows="10"><?php echo $row["Thread"] ?></textarea> <br/>
<!-- Here I have no clue how to deal with them... :( -->
Image : <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input type="file" id='ImageFieldToAdd' name="files[]" /> <br/>
<input id="submit" type="submit" name="submit" value="Upload me!">
and this is the information I store in MySQL
$title = $_REQUEST['TitleFieldToAdd'];
$thread = $_REQUEST['ThreadFieldToAdd'];
$file_content = file_get_contents($_FILES['files']['tmp_name'][0]);
$file_content = mysql_real_escape_string($file_content);
$file_name = $_FILES['files']['name'][0];
$file_size = $_FILES['files']['size'][0];
$file_type = $_FILES['files']['type'][0];
$datePosted = date("Y-m-d");*/
The proper way is to leave your file upload stuff asis. If a file has already been uploaded, you display it another section of the form. Imgs can be embedded with an <img> tag (pointing at another script which retrieves/serves up the raw image data from the database). Non-displayable fields (pdf, zip, etc..) you can just put in a direct download link.
Then your form will look something like
[input1]
[input2]
You previously uploaded: [link/image to uploaded data]
[input file] - would you like to replace this data?
As such, your form building script would not actually retrieve the uploaded file data. Just its metadata (type/size).