Get pdf file name from a URL in PHP - php

I want to get the pdfname from a URL generating the pdffile....
here is the link
$pdflink = "http://example.com/a.php?action=getSubmissionPDF&sid=".$sid."&formID=".$formid;
$pdflink is having the sid i.e form submission_id... with this sid name of the pdf file is generated
when i click on this url the pdf is generated with the name of $sid.pdf like 34556677.pdf
how I got the pdf name from this url??
I want to save this pdf file in infusionsoft filebox..
$filename=$_GET['sid'].".pdf";// filename
$contactId=5865;//contactid
$dataEncoded = base64_encode($pdflink);
$uploadFile = $app->uploadFile($filename, $dataEncoded, $contactId);
from this code the file is opladed in filebox bt not able to open the file because it shows the file is damaged and error msg it generates
when i download the file from filebox then it displays file is damaged not able to open the file in adobe...

use this to get sid value from url $_GET['sid']

Related

Laravel - Store uploaded image path in database,retrieve and display the image

I stored a picture in the uploads folder of my laravel project, I have an image table that has column name filename as a string type, how can i save the uploaded image location in the filename column and then output in my photos blade file based on the file location in my db
This is the code I used to store my image in my uploads folder
$filename = $file1->getClientOriginalName();
$picture = date('His').$filename;
$file1->move($destinationPath, $picture);
Below is the steps I did regarding upload and retrieve user related images.
For the example, a user upload his profile picture which named myfile.png
So, for upload:
Get the file from $request
Get the file name with getClientOriginalName() (i.e. myfile) and also the file extension with getClientOriginalExtension() (i.e. .png)
Generate some random strings which will be appended to the file name to avoid file name duplication (i.e. fx7ew6)
Append the original file name with the generated random strings along with the extension (i.e. myfile_fx7ew6.png)
Save image file to folder (i.e. public/img) and also save the file name to the database
For retrieve:
You can use <img src="/img/{{FILE_NAME}}"> to show the uploaded image which will result <img src="/img/myfile_fx7ew6.png"> IF you upload the image to public/img.

viewing a document stored as BLOB datatype in document viewer?

i have a website in which when a user uploads a file or document it is stored in database in BLOB datatype.
Also there is a download link which retrives the document from database and lets the user download.
now i want this document to be viewed in a document viewer like google doc viewer,how do i go about doing this ?
if you know the type of the file being downloaded you can use some thing like
Simple example:
$blob = "some data";
header('Content-type: image/jpeg'); // e.g. if a JPEG image
echo $blob;

File open/save as dialog and mime types

I am working on a simple document management system for a site - the user can upload around 20 different file types and the docs are renamed then stored in a folder above www, an entry is created in a docs table to capture meta data entered by the user and the item is then retrieved via another php file so the stored location for the files are hidden from the user.
When a user clicks to download a file using a simple a href it calls, for example, "view.php?doc=image.jpg" - when they do this currently the file opens in the browser so a jpg opens a window with pages of "wingdings" like characters etc.
I would like to be able to force a open/save dialogue box so the user decides what to do and my app doesn't try to open in the browser window with the above results.
From a previous posting I found I know I cannot pass the mime type in the "a href" tag so what other options do I have? Could I put header information into the below view.php file, for example?
$_file = $_GET['doc'];
$filename = './dir/'.$_file;
if (file_exists($filename)) {
echo file_get_contents('./dir/'.$_file);
} else {
echo "The file $_file does not exist";
}
;
You could use get_headers() to get the MIME type header of the desired file, and then use header() to output those headers into the file you're showing.
Alternatively, to simply force downloads, this:
header('Content-Description: File Transfer');
header("Content-type: application/octet-stream");
Should do it.

saving image from a webpage + saving its name too using PHP

how can i save an image from a web page , for example:
http://othersdomain.com/image/colorful.jpg
How can i save the image and save it to my directory "image" inside FTP.
and also get the "colorful" name from the link.
As a conclusion , it will get colorful.jpg and save in my directory with the same name and type then echo out the link to it(on my web server).
after being saved to my server , it will echo out somehting like this:
http://mydomain.com/image/colorful.jpg
You can get a file from another server using file_get_contents.
$file = file_get_contents('http://othersdomain.com/image/colorful.jpg');

How to recieve & store an image file from another server, being passed programatically with paramaters?

I am using the API of an image editing website (pixlr.com) for use by members of my site. I open Pixlr.com in an iframe where they can create an image and upon SAVE, pixlr sends the image file by use of parameters.
I want to save these image files (unique for each member) in a folder on my server (or on Amazon's S3 image server), using PHP. How do I receive their parameters ("image") of the image file and store them on my/Amazon's image server?
If the image is sent to your PHP script via POST, then you should be able to do something like this:
$handle = fopen($imageName, "wb");
fwrite($handle, $_POST["image"]);
fclose($handle);
Where $imageName is the absolute path and filename of the image where you want to save it (make sure you Apache user has write permissions to that directory). Depending on the picture's encoding you may need to figure out which extension to save it with (ie .jpg, .bmp, .png, etc).
EDIT:
Looks like they are sending the image via $_FILES. Try this:
move_uploaded_file($_FILES["image"]["tmp_name"], "/home/path/domain.com/upload/". time() .".png");

Categories