I am new and I don't know where is the mistake, I think I have taken care the routes and all but still I am not sure. Please help me out.
So when I do localhost:8000/uploadfile/ it gives me this error
This site can’t be reached localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
And when I go through the detail URL it gives me:
the view[uploadfile] not found
This is my form:
<!DOCTYPE HTML>
<html>
<body>
<?php
echo Form::open(array('url'=>'/uploadfile','files'->'true'));
echo 'Select the file to upload';
echo Form::file('image');
echo Form::submit('upload file');
echo Form::close();
?>
</body>
</html>
My controller is:
<?php
namespace App\Http\Controllers;
use App\files;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use App\Http\Controllers\Controller;
class UploadFileController extends Controller {
public function index() {
return view('uploadfile');
}
public function showUploadFile(Request $request) {
$file = $request->file('image');
//Display File Name
echo 'File Name: '.$file->getClientOriginalName();
echo '<br>';
//Display File Extension
echo 'File Extension: '.$file->getClientOriginalExtension();
echo '<br>';
//Display File Real Path
echo 'File Real Path: '.$file->getRealPath();
echo '<br>';
//Display File Size
echo 'File Size: '.$file->getSize();
echo '<br>';
//Display File Mime Type
echo 'File Mime Type: '.$file->getMimeType();
//Move Uploaded File
$destinationPath = 'uploads';
$file->move($destinationPath,$file->getClientOriginalName());
}
}
Finally my route:
Route::get('/uploadfile','UploadFileController#index');
Route::post('/uploadfile','UploadFileController#showUploadFile');
You should try this:
your view file like:
Path:
yourproject folder/resources/views/uploadfile.blade.php
<form class="form-bordered" action="{{url('/uploadfile')}}" method="POST">
<div>
<lable>Select the file to upload</lable>
<input type="file" name="image">
<input type="submit" value="upload file">
</div>
</form>
Related
I am using google-drive-sdk to upload a pdf file (dynamically generated in the php web app) to Gdrive.
About my app
On click of submit button the users see a THANKYOU displayed on the page. At the background
pdf file gets generated
and this file needs to be uploaded to Gdrive account --(configured the client id & secret key for the app in Google Console)
:
I am able to upload to the configured GDrive but first time to authenticate I run the url(redirect url given in Google Console) in browser(*say
http://localhost:3422/wordpress/wp-content/plugins/mktProc/google-api-php-client/gDrive_access/pdf_results_upload.php
*)
This takes me to GDrve page and prompts Allow\Deny Access.
I click Allow and then am able to upload to Grdive.
But I would like this to happen without prompts for Allow\Deny for the user to interact.
Please give me details on what I need to add so that when user clicks the Submit button , automatically the generated file gets inserted to GDrive.
I read lot in net but couldn't understand and get it to work.
Please help me with steps and code to include.
The code I am using
<?php
include_once "templates/base.php";
if(!session_id()){session_start();}
require_once realpath(dirname(__FILE__) . '/../autoload.php');
$pdf_filename='';
try
{
if(isset($_SESSION['pdf_filename']) && $_SESSION['pdf_filename'])
$pdf_filename=$_SESSION['pdf_filename'];
}
catch(Exception $ex)
{
echo ("This is for GDrive Upload from CalWeb");
}
$pfdStoragePath=dirname(__FILE__)."/../../vendor/pdf/".$pdf_filename;
/************************************************
ATTENTION: Fill in these values! Make sure
the redirect URI is to this page, e.g:
http://localhost:8080/fileupload.php
************************************************/
$client_id = 'xxxx.apps.googleusercontent.com';
$client_secret = 'xxxxSB0tNVy';
$redirect_uri = 'http://localhost:3422/wordpress/wp-content/plugins/mktProc/google-api-php-client/gDrive_access/roi_results_upload.php';
$client = new Google_Client();
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->addScope("https://www.googleapis.com/auth/drive");
$client->setAccessType("offline");
$client->setApprovalPrompt('force');
$service = new Google_Service_Drive($client);
if (isset($_REQUEST['logout'])) {
unset($_SESSION['upload_token']);
}
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['upload_token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if (isset($_SESSION['upload_token']) && $_SESSION['upload_token']) {
$client->setAccessToken($_SESSION['upload_token']);
if ($client->isAccessTokenExpired()) {
unset($_SESSION['upload_token']);
}
} else {
$authUrl = $client->createAuthUrl();
}
/************************************************
If we're signed in then lets try to upload our
file.
************************************************/
try {
if ($client->getAccessToken()) {
if($pdf_filename!=="")
{
$file = new Google_Service_Drive_DriveFile();
$file->setTitle($pdf_filename);
$file->setDescription('Document');
$file->setMimeType('application/pdf');
$result = $service->files->insert(
$file,
array(
'data' => file_get_contents($pfdStoragePath),
'mimeType' => 'application/pdf',
'uploadType' => 'multipart'
)
);
//echo $result->webContentLink;
$pdf_filename="";
unset($_SESSION['pdf_filename']);
}
//if (isset($result) && $result) $_SESSION['webContentLink']=$result->webContentLink;
//echo $result->webContentLink;
}//if ($client->getAccessToken()) {
} catch (Exception $ex) {
echo '';
}
?>
<div class="box">
<div class="request">
<?php if (isset($authUrl)): ?>
<a class='login' href='<?php echo $authUrl; ?>'>Connect Me!</a>
<?php else: ?> <?php echo "Access Allowed" ?>
<?php endif; ?>
</div>
<?php if (isset($result) && $result): ?>
<div class="shortened">
<?php echo "aaa"; ?>
<?php echo $result->webContentLink; ?>
<?php echo "bbb"; ?>
</div>
<?php endif ?>
<?php if($pdf_filename==="") ?>
<?php echo "This is for GDrive Upload from MiniROI" ?>
</div>
how to Load Text file into HTML, inside tag?, I don't have an source to show you.
thanks
You can use PHP to load files from the user's computer. Here is an example.
form.html
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
upload.php
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
if(isset($_POST["submit"])) {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
header("Location: http://example.com/displaymessage.php?filename=" + basename( $_FILES["fileToUpload"]["name"]));
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
displaymessage.php
<?php
$file = $_GET['filename'];
?>
<script>
var client = new XMLHttpRequest();
client.open('GET', '/uploads/<?=$file?>');
client.onreadystatechange = function() {
document.getElementById("#textbox").value = client.responseText;
}
client.send();
</script>
Make sure to change #textbox, to the ID of the textarea tag. (e.g. <textarea id="foo">)
NOTE: I just came up with half of this code, and I am not sure if it will work
I'm trying to build a form in Codeigniter so that its elements are part of a table and are therefore aligned nicely. Here's the view page:
<div id="login">
<h3>Log in</h3>
<?php
$attributes = array('id'=>'form_login');
echo validation_errors();
echo form_open('login/main', $attributes);
//probably a bad idea to load libraries in views, but what the heck?!
$this->load->library('table');
$this->table->add_row('Username', form_input('username'));
echo $this->table->generate();
//echo 'Username: ';
//echo form_input('username') . '</br>';
echo 'Password: ';
echo form_password('password') . '</br>';
echo form_submit('submit', 'Log in');
?>
<br/><br/>
Forgot Password <br/>
New User? Register
</div>
The two lines commented out is how it was earlier. Now I'm getting the following error: Call to a member function add_row() on a non-object. Why is table a non-object? I've tried loading the library in the controller but the error persists. Please help!
In codeigniter, the global codeigniter object is not available in your views, so you have to get a reference to it.
Try the following
$ci =& get_instance();
Put that at the top, and replace your calls to $this like so:
$ci->load->library('table');
$ci->table->add_row('Username', form_input('username'));
echo $ci->table->generate();
I am trying to take some html from a textarea and convert it to a pdf. I donwnloaded DOMPDF from https://github.com/dompdf/dompdf and wrote the code below. When I click submit I get this error: "Internal Server Error". (my webhost doesn't tell me which line it's one)
(the name of this file is test2.php)
<?php
if (isset($_POST['submit'])) {
$content = $_POST['content'];
if (empty($content)){
$error = 'write something';
}
else {
include_once( 'dompdf/dompdf_config.inc.php' );
$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->render();
$dompdf->stream('example.pdf');
}
}
?>
<!DOCTYPE html>
<head>
</head>
<body>
<?php
if(isset($error)){
echo $error;
}
?>
<form method="post" action="test2.php">
<textarea name="content" id="content">hello world</textarea><br>
<input type="submit" name="submit" value='submit'>
</form>
</body>
</html>
I was struggled for more than one month to solve this. Finally I solved it. the solution is below.
<?php
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
?>
<html>
<head></head>
<body>
<h1>Sucess</h1>
</body>
</html>
<?php
$html = ob_get_clean();
$dompdf = new DOMPDF();
$dompdf->setPaper('A4', 'portrait');
//$dompdf->setPaper('A4', 'landscape');
$dompdf->load_html($html);
$dompdf->render();
//For view
$dompdf->stream("",array("Attachment" => false));
// for download
//$dompdf->stream("sample.pdf");
?>
I had a similar issue on a client's server when using DOMPDF for a project.
It's possible that you do not have the right level of error reporting configured with your installation of PHP.
At the top of your script place the following; error_reporting(E_ALL);
Example:
error_reporting(E_ALL);
if (isset($_POST['submit'])) {
$content = $_POST['content'];
if (empty($content)){
$error = 'write something';
}
else {
include_once( 'dompdf/dompdf_config.inc.php' );
$dompdf = new DOMPDF();
$dompdf->load_html($content);
$dompdf->render();
$dompdf->stream('example.pdf');
}
}
You should now see a more detailed message about the type of error received.
There could be issues with the HTML markup you are passing to the $dompdf->load_html($content); method or alternatively you might be experiencing memory related issues (exceeding your memory allowance).
Typically these errors will report themselves but again depending on your setup, reporting might be limited.
How could I add a logout link in the else portion of code, after the "echo $upme->display();" ...
<?php
global $upme;
if (!is_user_logged_in()) {
echo $upme->show_registration();
echo $upme->login();
}
else { echo $upme->display();
}
?>
I tried a few things including the below code but I keep getting internal error ...
<?php
global $upme;
$html1 = 'Logout';
if (!is_user_logged_in()) {
echo $upme->show_registration();
echo $upme->login();
}
else { echo $upme->display();
echo $html1;
}
?>
Thank You
There's a small syntax error:
$html1 = 'Logout';
500 is generally an "I can't find that" error. What page is this from? get_permalink may be returning false. Try outputting that function to see what you get back.
<?php echo get_permalink(); ?>