Hello every one i m using fpdf libray to creat pdf files from html form.
i m using
$pdf->Image('C:/DOCUME%7E1/mypic.PNG',60,140,120,0,'','');
to display image on pdf.
in its first parameter it asks for exact path.it doesn't accept anyaddress variable here.
but i want to make dynamic.i have able to get a complete path in an variable.
i have printed this variable.
//////////////////////////////
echo "$path";
output
////////////////////
C:/DOCUME%7E1/mypic.PNG
/////////////////////////////////////////////////////
but how i put that path from variable in this parameter.?
when i use this variable as in this function.it give error.
$pdf->Image('$path',60,140,120,0,'','');
plz help me for this.
$pdf->Image($path,60,140,120,0,'','');
This should work.
I removed the single quotes from the variable.
OR
put the $path in double quotes:-
$pdf->Image("$path",60,140,120,0,'','');
Remove the single quotes wrapping the variable name.
The single quotes make PHP treat your string as a literal (i.e. $path instead of C:/DOCUME%7E1/mypic.PNG).
Confusingly, it would work with double quotes because of variable interpolation.
Related
I am building a web application using CodeIgniter framework. The issue is that while uploading a file that have a single quote ' in the file name (Eg : Rob's.wmv) I get an empty file array in the controller. CI do have code to update the file name when the name contains special characters, but since the array is not set correctly the uploading doesn't take place. I can't understand what's going on, I tried debugging, it appears the uploading works fine on my local machine, but not on the server, this makes it even more interesting.
UPDATE The file array var_dump returns an empty array, so there's no way I can even get the file name in the script. The file array is not set, I don't get any information about the file at all.
You have to use the addslashes() from php.
The addslashes() function returns a string with backslashes in front of predefined characters.
example:
$var = "Rob's.wmv";
//then
$var = addslashes($var);
The predefined characters are:
single quote (')
double quote (")
backslash (\)
NULL
Tip: This function can be used to prepare a string for storage in a database and database queries.
As you upgrade your question:
please read this two article carefully, this is just a configuration problem. After that i think you are able to do it.
codeigniter-file-upload
how-to-upload-file-in-codeigniter
I am not able to delete the files from a folder using php whenever the user clicks yes to delete form submission.
The files are still present in the folder even after using unlink() function:
<form method='post'>
<input type='submit' name='del' value='Yes'>
</form>
<?php
if(isset($_POST['del']))
{
$filename=$userid.".jpg";
unlink('upload-cover/uploads/$userid/$filename');
echo "Your image has been deleted successfully!!";
}
?>
You have to have the string passed to the unlink function in double-quotes. This is because PHP will interpret strings in single-quotes literally, therefore not including your variables. Try this:
unlink("upload-cover/uploads/$userid/$filename");
Or:
unlink("upload-cover/uploads/".$userid."/".$filename);
I think the second option is a lot more readable, and prevents errors like the one you encountered!
This is a great answer to understand PHP strings and paths:
What is the difference between single-quoted and double-quoted strings in PHP?
If you use single quotes, the file name genrated will be incorrect.
Also, make sure you have right permissions
Try with
unlink("upload-cover/uploads/$userid/$filename");
By looking into your code it seems that it is variable look up problem
variable inside single quotes are string to the php engine
unlink('upload-cover/uploads/$userid/$filename');
where as variable inside double quotes are variable to the php engine
unlink("upload-cover/uploads/$userid/$filename");
This should be incredibly simple but i can't seem to figure it out.
I have the following code
<?php
$bookingid='12345';
include_once('phpToPDF.php') ;
//Code to generate PDF file from specified URL
phptopdf_url('https://google.com/','pdf/', $bookingid.pdf);
echo "<a href='pdf/$bookingid.pdf'>Download PDF</a>";
?>
It echo's correctly however when it comes to generate the pdf...
phptopdf_url('https://google.com/','pdf/', $bookingid.pdf);
...it misses out the fullstop so it generates 12345pdf whereas it should be 12345.pdf.
Again, i apologise for the probable simplicity of this but i can't seem to figure it out.
$bookingid.pdf
It tells php to concatenate variable $bookingid with constant pdf. Since constant pdf is undefined, it is casted to string and concatenated. Proper code will look like:
$bookingid . '.pdf'
or
"$bookingid.pdf"
This should be
$bookingid.".pdf"
PHP is seeing a string concatenation, concatenating pdf' to $booking. pdf is an undefined string, so PHP helpfully assumes that you mean the text itself, but it misses the full stop you also need.
I've seen tutorials over the internet for this, but I cannot get it to work.
I've got this in a while loop, but it shouldn't matter:
while($row = mysql_fetch_object($result)){
$image_url = $deviceimg.($row->Image);
if(!file_exists($image_url))
{}
else {
$image_url = 'images/android.png';
}
Basically, im my database, all the rows called Image are populated, but only some of them have an actual file. What im trying to do is check to see if the image file actually exists on the server, if it doesn't use a default image (images/android.png)
No matter that I do, it will either replace ALL images with the default, or it will just use the URL in the database, regardless of if the file actually exists.
The reason you have a problem is because you have wrapped $image_url in single quotes when you pass it to file_exists(). This is checking whether there is a file file literally named $image_url, instead of using the contents of the variable.
Change
if (!file_exists('$image_url'))
to
if (!file_exists($image_url))
and it will work.
'$image_url' does not get parsed to the contents of the variable $image_url: it will stay the same string literal.
Remove the quotes. Only variables in double quotes ("$image_url") will get parsed.
copy('https://graph.facebook.com/$fbid/picture?type=large', 'images/$fbid.jpg');
i am using the above code to store the image locally ..
the above code works without the variable. As it does not executes php in it so it is useless with links containing php variables....
The code works with a definite url is provided...
i wanna use the above url of source and destination respectively to get image...
please suggest me any other workaround or way that allows the links with variables to be executed ....
Your strings are wrapped in ' ', to use variable interpolation, you need to wrap yours strings in " ", so copy("https://graph.facebook.com/$fbid/picture?type=large", "images/$fbid.jpg"); will work.
Also, to make it clearer, it's possible to wrap your variables in { }, so "Hello {$world}" will, assuming $world contains "World", print "Hello World".
There's a few other gotchas, so have a look over the PHP manual page for strings I've put at the bottom of this post.
Ref: http://php.net/manual/en/language.types.string.php