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.
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 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
}
?>
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
hy developers, i want to download multiple files as a zip, but i keep getting errors
below is the code i have tried
public function multiple($id){
$files = documents::where('claim_id', $id)->get();
if ($files != '') {
$filepath = storage_path('app/Documents/');
foreach($files as $file) {
$zipper = new \Chumper\Zipper\Zipper;
$fi = storage_path('app/Documents/'.$file->file_name);
$zipper->make($filepath.'doc.zip');
}
return response()->download($filepath.'doc.zip');
}
else{
Alert::info('Info', 'No Documents Available');
return redirect()->back();
}
}
attached is the error i get
Looks like you didn't add any files to your Zip.
I think:
$zipper->make($filepath.'doc.zip');
Should be:
$zipper->make($filepath.'doc.zip')->add($fi)->close();
Make sure the files and zip are in the storage folder.
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 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 have a folder in my website, is it possible to check if a file exist for comparing with a data query ?
I mean if $donnees["DATA"] == one of the files of the folder.
I don't know any function or something about that.
For instance if Data = 25478
In my folder :
Differents name of file :
24788
24777
25478
$listOfFiles = glob("*");
if(in_array($donnees["DATA"], $listOfFiles) {
//do stuff
}}
You can use glob("*.txt") for .txt files etc etc.
Yes, you can use glob function:
//path to directory to scan
$directory = "somefolder/";
//get all folders/files in specified directory
$files = glob($directory . "*");
//get ach directory/file name
foreach($files as $file)
{
if($donnees["DATA"]==$file){
//do something
}
}
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