<!DOCTYPE html>
<html>
<head>
<title>Centrum Homepage</title>
</head>
<body>
<div id="logo">
<h1>WELCOME TO CENTRUM</h1>
</div>
<div id="instruction">
Enter a path on the filesystem to search for media
</div>
<div id="search-div">
<form action="index.php" method="post">
<input type="text" name="search-bar">
<input type="submit" name="search-submit" value="Search Path">
</form>
<?php
// You can add any file you want to search for, keep in mind, the default ones are the only ones supported by HTML5 players
$ImageFormats = array('jpeg', 'jpg', 'png');
$MusicFormats = array('mp3', 'wav');
$VideoFormats = array('mp4', 'webm');
$ImageFound = array();
$MusicFound = array();
$VideoFound = array();
if(isset($_POST['search-submit'])){
$path = $_POST['search-bar'];
if (!file_exists($path)) {
echo "Path not found. Please try another path.";
} else {
// If Path is valid, search for media in folders and sub folders and add them to arrays
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)) as $filename)
{
if(in_array(pathinfo($filename, PATHINFO_EXTENSION), $ImageFormats))
array_push($ImageFound, $filename);
elseif(in_array(pathinfo($filename, PATHINFO_EXTENSION), $MusicFormats))
array_push($MusicFound, $filename);
elseif(in_array(pathinfo($filename, PATHINFO_EXTENSION), $VideoFormats))
array_push($VideoFound, $filename);
}
if (empty($ImageFound))
echo "No Image found";
else {
echo "We found " . count($ImageFound) . "image files" . "<br>";
echo '<form action="photos.php" method="post">';
echo '<input type="image" src="images/photo.png" \>';
echo "</form>";
}
if (empty($MusicFound))
echo "No Music found";
else {
echo "We found " . count($MusicFound) . "Music files" . "<br>";
echo '<form action="music.php" method="post">';
echo '<input type="image" src="images/music.png" \>';
echo '<input type="submit" name="submit-music" value="View Music" \>';
echo "</form>";
}
if (empty($VideoFound))
echo "No Video found";
else {
echo "We found " . count($VideoFound) . "video files" . "<br>";
echo '<form action="videos.php" method="post">';
echo '<input type="image" src="images/video.png" \>';
echo '<input type="submit" name="submit-videos" value="View videos" \>';
echo "</form>";
}
}
}
?>
</body>
</html>
All arrays store huge number of paths on the machine. This script is gonna run on raspberry pi, no MySQL. I tried writing to a file the var_dump
you can think of an array thousands of strings similar to
/home/Desktop/centrum/1.mp3
I tried to save it in a session, it doesn't get saved, is there a way to save it to a session without messing with the data? the data can't be serialized just the simplest way to put in in a session? before playing with a database.
if i write $sm = serialize($MusicFound);
before
if (empty($ImageFound))
I get
Fatal error: Uncaught Exception: Serialization of 'SplFileInfo' is not allowed in /opt/lampp/htdocs/web/centrum/index.php:60 Stack trace: #0 /opt/lampp/htdocs/web/centrum/index.php(60): serialize(Array) #1 {main} thrown in /opt/lampp/htdocs/web/centrum/index.php on line 60
and this question states that I'm getting my error because I cant serialize