Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a website, where the user can write PHP/HTML code and save it to his computer. Everything is fine until the user types a slash (/).
The file saves into the client computer, but instead of saving the client code, it exports an PHP error (the file in the computer has a PHP code of an error). The file-saving code is the following:
$content = $_REQUEST['code']; //Get the code
$file = "file.php";
file_put_contents($file, $content); //Writes the content into a file
header('Content-type: text/plain');
header('Content-Disposition: attachment; filename=$file');
readfile(dirname(dirname($con)) . '/'.$file);
The error only happens when the client uses slashes.
Any idea on why is this happening? )-:
EDIT:
This is one of those errors:
The code that i tried to export was the following:
/:
The thing that worries me, is that if I type exactly the same characters in different order (:/) then they export to my computer with no errors.
I see only one error - problem with readfile(\/105.2.php) in line 24 - so I tested it.
$file = 'file.php';
$con = '/:';
readfile(dirname(dirname($con)) . '/'.$file);
It gives me incorrect path \/file.php as in error message.
If I use $con=':/' it gives me correct path ./file.php
I only don't know what $con is. Maybe you have dirname(dirname($content)) in your oryginal code and $content = $_REQUEST['code']; => dirname(dirname($_REQUEST['code'])) => dirname(dirname("/:")) => "\"
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
I have a little problem I try to display a url image that there is in my phpmyadmin database, but nothing is displayed. I am trying to display an image from my database. I put you my code and my line of the database. Thank you in advance for your help !
see if I made a mistake in the code, or if I used the wrong path
the URL of my image is called "img_l" in my database and it is in a category called "liste"
Voici mon code :
<?php
$bdd = new PDO('mysql:host=localhost;dbname=animebd;chaset=utf8','root','');
$req = $bdd->query('SELECT img_l,nomL FROM liste');
while($donnees = $req->fetch()){
echo('<img style="width:50px;height:50px;border-radius;:500px;" img_l = "' . $donnees['img_l'] . '"/><br/>');
}
?>
In image tag, you don't have src attribute. You must add it and concatenate your data from db with images directory.
$path = './public/images/' . $donnees['img_l'];
of course my answer is valid only if $donnees['img_l'] is the filename with extension (mycar.jpg)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
So for my program to run it needs a certain type of file. This file is called a .fasta file. This type of file has a specific type of heading. It looks like this.
>gi|129295|sp|P01013|OVAX_CHICK GENE X PROTEIN (OVALBUMIN-RELATED)
My program gets text input from a user and puts it into a file. The problem that I have is that the file just contains the string from the user. My program can't read in just a string, the file needs to have that header on the first line and the string on the second line. Is there anyway to format a file so that the user input goes onto the second line?
Here is the html and php of when the user's input is changed into a file. So the text in the text box is created into a file but I need that header on the first line! Thanks in advance.
<input id="BlastSearch" type="text" name="BlastSearch" value='' />
php
<?php
$sequence = $_POST['BlastSearch'];
$file = 'uploads/new.fasta';
$current = $sequence;
file_put_contents($file, $current);
?>
This creates a file with the text on the first line
So basically I need the header on the first line of the file and then the user input on the second line of the file. Thanks in advance!
Just append the value before the user input then send it to the file.
<?php
$header = "Header Data Stuff\n";
$sequence = $header . $_POST['BlastSearch'];
$file = 'uploads/new.fasta';
file_put_contents($file, $sequence);
?>
There also didn't seem to be a need for this variable assignment so I removed it, $current = $sequence;.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Ok, I've got class with function that is load text from txt file. Function load line print "Some kind of text", but I want to run this (so I'll got Some kind of text)
<?php
class LoadFile
{
//Funkcja to load file
public function wykonaj()
{
$fp = fopen("link", "r");
$tekst = fread($fp, 25);
$szukaj = "print"
echo $tekst;
}
}
$Test = new LoadFile();
$Test->wykonaj();
?>
I assume what you want to do is to use the file as a PHP script. Why not use proper includes then?
Another solution is to use the eval() function, but then look at the doc carefully and be aware how dangerous it is.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am using a cross domain request.A request has been made to php file in a server via ajax from another server.From php side Here, I need to create a file and write some contents in that file.My request is reaching perfectly.But I am not able to create a file.Please help
NOTE : ITS A CROSS DOMAIN REQUEST
<?php
$filename = "lin.txt";
$data2 = "lin IS HERE";
$newFile= fopen($filename, 'w');
chmod($newFile, 777);
fwrite($newFile, $data2);
fclose($newFile);
?>
Thanks in advance
In am not sure what are you going to do, because you haven't told us your code. I think this will help you:
<?php
$file = 'demo.txt';
$content = "Example\n";
file_put_contents($file, $content);
?>
The file is demo.txt (it is at the same location with the PHP document.
$content is the text which will be put on your txt file.
Hope it helps!
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am using a script to back up files from ftp. code is below.
include "recurseZip.php";
//Source file or directory to be compressed.
$src='source/images/black.png';
//Destination folder where we create Zip file.
$dst='backup';
$z=new recurseZip();
echo $z->compress($src,$dst);
Now I want to get values to $src from source/files.txt which contains a list of file names.
My .txt file:
index.php.bk-2013-12-02
index.php.bk-2013-12-07
index.php.bk-2013-12-10
index.php.bk-2013-12-20
index.php.bk-2013-12-26
function.php.bk-2013-12-20
function.php.bk-2013-12-23
contact.php.bk-2013-12-23
contact.php.bk-2013-12-30
my source/files.txt contains 10 file names those need to be assigned as values to the variable $src I am using this script http://ramui.com/articles/php-zip-files-and-directory.html
how can I do that.?
any help will be very much appreciated.
Thanks.
Okay, you want to get the file name from each line of the .txt file.
<?php
$myFile = "files.txt";
$lines = file($myFile);
foreach($lines as $line){
$file = basename($line);
echo $file;
}
?>
Answer to your old question variant
You can use the basename() function. The manual says, "given a string containing the path to a file or directory, this function will return the trailing name component".
Now, you said "I want to get file name to $src from source/files.txt", so assuming from this, you are looking to get the file name i.e. black.png. This could be achieved using the basename() function as mentioned before.
<?php
$src='source/images/black.png';
$file = basename($src);
echo $file;
?>
Output
black.png
http://ideone.com/p2b4sr