PHP code is displayed instead of the output - php

Can someone please explain this code, i am following a very good book that was recommended to me and I have typed the code exactly as it is in the book. it displays the code instead of out, I am not sure what is wrong, the code is from a book called php solutions
<?php
// set the max upload size in bytes
$max = 51200;
if(isset($_POST['upload'])){
// define the path to the upload folder
$destination = 'C:\upload_test';
// move the file to the uplaod folder and rename it
move_uploaded_file($_FILES['image']
['tmp_name'], $destination.$_FILES['image']['setara']);
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Mult</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<form action="" method="post" enctype="mutipar/form-data" id="uploadImage">
<p>
<label for="image">Upload image:</label>
<input type="hidden"name="MAX_FILE_SIZE" value="<?php echo $max; ?>">
<input type="file" name="image" id="image">
</p>
<p>
<input type="submit" name="upload" id="upload" value="Upload">
</p>
</form>
</body>
</html>

This is surely because you are writing PHP code in .html or .htm extension file try putting the code with .php extension file. It will resolve error.

Related

Uploading image using php results in accept-file.php was not found

Hi im trying to upload an image to a database using php but every time i press the submit button i get the error
accept-file.php was not found
i dont see anywhere in my code where it will be directing to that is there something im missing?
<?php
session_start();
$link = mysqli_connect("localhost","root","","pictureupload");
if(isset($_POST['submit'])){
$imagename=$_FILES["iamge"]["name"];
$imagetmp=addslashes (file_get_contents($_FILES['image']['tmp_name']));
$insert_image="INSERT INTO images VALUES('$imagetmp','$imagename')";
mysqli_query($link,$insert_image);
}
?>
<!DOCTYPE html>
<html>
<head>
<Title>HomePage</Title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<form action="accept-file.php" method="post" enctype="multipart/form-data">
Your Image: <input type="file" name="image" size="25" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
change your form tag to
<form action="?"
Your form has "accept-file.php" set as action:
<form action="accept-file.php" method="post" enctype="multipart/form-data">
This is where the form data will be sent to via the set method (POST in this case) and using the given encoding type.
After you click on "submit" your browser will call this script, which in your case does not exist. Therefore your webserver will return the error message instead of handling the upload.
To make it work you need to change the action to the filename of your script, which you have posted above.

How to set PHP Cookie Pixel using img tag

I'm trying to save cookie using img tag. I used img tag in thankyou.php and wrote cookie related code in pixel.php file.
These three files are in the same directory(Folder Name: landing).
Here is index.php file code.
<html>
<head>
<title></title>
</head>
<body>
<form action="thankyou.php" method="GET">
<input type="text" name="name" placeholder="Name" required />
<input type="email" name="email" placeholder="email" required />
<input type="submit" value="Subscribe" />
</form>
</body>
</html>
Here is thankyou.php file code.
<html>
<head>
<title></title>
</head>
<body>
<h3>You've successfully subscribed for this campaign.</h3>
<img alt="" width="1" height="1" style="display:none" src="pixel.php?e=<?= $_GET['email'] ?>&c=book_bonus_video_1" />
</body>
</html>
Here is pixel.php file code.
$sCampaign = # $_GET['c'];
$sCampaign = urldecode($sCampaign);
$sEmail = # $_GET['e'];
$sEmail = urldecode($sEmail);
setcookie('campaign_' . $sCampaign,strtolower($sEmail),time()+60*60*24*365,'/');
header('Content-Type: image/gif');
die(base64_decode('R0lGODlhAQABAJAAAP8AAAAAACH5BAUQAAAALAAAAAABAAEAAAICBAEAOw=='));
When I submit form(index.php), thankyou.php page is opened but cookie is not created. But when i write URL ( http://www.example.com/landing/pixel.php?e=user#email.com&c=book_bonus_video_1 ) in browser it creates cookie.
I don't know where is issue in my code.
Thanks in advance for guiding me.

adding uploader to php script [duplicate]

This question already has answers here:
Why would $_FILES be empty when uploading files to PHP?
(22 answers)
Closed 8 years ago.
Regarding this ...... question but......... still learning :3
so i have a php file lets say called x.php and all working i would like to add uploader so people can upload txt files ....... but i dnt want to have another file which is uploader.php
Thnx in advance......
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<center>
upload ur CV.<br>
<form action="same.php" method="post"><br>
<input type="file" name="uploadFile">
<input type="submit" value="Upload Wordlist">
</form>
</body>
</html>
</center>
<?php
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}")
?>
Your form lacks "enctype="multipart/form-data" in
<form action="same.php" method="post"> which should read like this
<form action="same.php" method="post "enctype="multipart/form-data">
This is an essential part of uploading files.
Consult the manuals:
http://php.net/manual/en/function.move-uploaded-file.php
http://php.net/manual/en/features.file-upload.post-method.php
Plus, make sure that the folder is writeable and with proper permissions set.
Edit:
<html>
<head>
<title>File Upload Form</title>
</head>
<body>
<center>
upload ur CV.<br>
<form action="" method="post" enctype="multipart/form-data"><br>
<input type="file" name="uploadFile">
<input type="submit" name = "submit" value="Upload Wordlist">
</form>
</body>
</html>
</center>
<?php
if(isset($_POST['submit'])){
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}");
}
?>

Videos won't upload

I'm trying to upload some videos using PHP.
But I can't get them into any folder.
I don't get errors, so I don't know where to start.
My code:
<?php
if(isset($_FILES['files']))
{
foreach ($_FILES['files']['tmp_name'] as $key => $tmp_name) {
move_uploaded_file($tmp_name, "upload/{$_FILES['files']['name'][$key]}");
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Uploading videos</title>
</head>
<body>
<div>
<form action="" method="post" enctype="multipart/form-data">
<p>
<input type="file" name="files[]" multiple="multiple" min="1" max="9999" />
<input type="submit" value="Upload" />
</p>
</form>
</div>
</body>
</html>
I'm trying to upload, .webm, .ogv and .mp4
The files aren't that big, they're just 5MB or something.
First I got this error in Apache log: POST Content-Length of 15236606 bytes exceeds the limit of 8388608. So I changed that limit from 8MB to 80MB and now that error is gone, but the files aren't uploaded yet. And there are no errors anymore.
When I try to send some images, I get them. Probably there is something not handled correctly. But I don't know what.
Thanks in advance for the help ;)
Bjorn
You'll want to up the following settings:
post_max_size
upload_max_filesize
memory_limit
Also set_time_limit to something high as well.

Require upload of a file in HTML/PHP form

I'm trying to require a file upload in a form, but cannot get it to work. Any ideas? I'd rather echo the php error on the page vs. a javascript popup. Thanks for taking a look:
<?php
// initialize $file1
$file1 = $_POST['file1'];
// check upload of $file1
if ($file1 == '' ) {
$error = "Please upload an image";
}
?>
<!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=UTF-8" />
<title>Require upload of an file</title>
</head>
<body>
<?php if ($error) {echo $error;} ?>
<br /><br /><br />
<form id="form1" name="form1" method="post" action="nextpage.php">
<input type="file" size="8" name="file1" />
<input name="Submit" type="Submit" />
</form>
</body>
</html>
See this tutorial it have all that you need.
To sum up:
Use enctype="multipart/form-data" and method="POST" in the <form> tag.
In PHP use $_FILES['uploadedfile']['name'] to read original name ("uploadedfile" is the name of your file input - "file1" in your example).
In PHP use $_FILES['uploadedfile']['tmp_name'] to read server side temp file name.
In PHP use $_FILES['uploadedfile']['error'] to get the error (if any) see there for possible codes.
Also see the PHP manual for more info.
In your exemple use this form instead:
<form id="form1" name="form1" method="post" action="nextpage.php" enctype="multipart/form-data">
<input type="file" size="8" name="file1" />
<input name="Submit" type="Submit" />
</form>
In "nextpage.php":
//Use $_FILES['file1'] to check the file upload...
print_r($_FILES['file1']);

Categories