Loading line as a code? [closed] - php

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.

Related

how to check if a folder or directory is exist on a remote path in php [closed]

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 2 years ago.
Improve this question
I am new to PHP, FTP connection.
I have to check a folder on a remote location ( ftp location ) that whether this folder exist or not.
I have tried through curl but it is not showing correct result.
maybe it would be easier to use an FTP PHP library , try this one php-ftp-library
try to use this code:
<?php
$path = 'your file name';
if (!is_dir($path)) {
//do something
} else {
//do something else
}
?>

Laravel Reading files in storage [closed]

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 4 years ago.
Improve this question
I have saved images in a file in the storage. I would like to get the files saved into an array using exec command in the controller and then pass the array into the blade. Is there any way to do it?
$images= [];
// $filesInFolder = \File::files('images'); getting files from the folder
$files = file_get_contents( 'filename' ); // replace here the filename with you full path of the file
foreach($files as $path)
{
$images[] = pathinfo($path);
}
Then you can pass the images/files in your blade.

How to assign a value to a variable from a text file? [closed]

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

Can not delete image file on server but other files can [closed]

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
You are right some people are really blind and dumb.
I think that your problem is the file permission.
You must change the file permissions of your images (0644 or 0777 in your chase).
Please read this: http://php.net/manual/en/function.chmod.php.
You can delete images in PHP using the unlink() function.
unlink('path/to/file.jpg');
See http://php.net/manual/en/function.unlink.php .
EDIT:
ALSO you can try this:
if(is_writable($filename))
{
unlink($filename)
} else {
echo 'At this moment this file can't be deleted';
chmod(" YOUR PATH OF $filename", 0777);
unlink($filename);
}
AND
if (file_exists('YOUR PATH OF $filename')) {
echo 'File exist... Sorrrrrrrrrry!!!!!!!!!!!!';
}

How do I not use the global include files in php [closed]

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
How can I simplify the inclusion of classes in the following code, without
use a global include files.
enter code here
<?php
include "class/class.Prode.php";
include "class/class.Groupes.php";
include "class/class.Pages.php";
include "class/class.Links.php";
$prod = new Prode;
$group = new Groups;
$page = new Pages;
$link = new Links;
?>
Please explain and refer to articles describing this.
You want to look at PHP's Autoload: http://php.net/manual/en/language.oop5.autoload.php
It will significantly help simplify your inclusion process!
Use autoloading of classes as described in the PHP manual.
You need to be using PHP's autoload function, I have included an example below for you.
function __autoload($class_name) {
$class_name = strtolower($class_name); // you may need to omit this or rename your files
$file = "class.{$class_name}.php";
$directory = "/path/to/your/class/directory/";
if($full_path = recursive_file_exists($file, $directory)) {
require($full_path);
} else {
// check if it exists with an s on the end
// a nice fallback to cover forgetfulness
$file = "class.{$class_name}s.php";
if($full_path = recursive_file_exists($file, $directory)) {
require($full_path);
} else {
die("The file class.{$class_name}.php could not be found in the location ".$directory);
}
Hope that helps you on your way.

Categories