Call xargv in php


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Call xargv in php

Hello,
After I loose all my works/files couple days ago, I am trying to fix them with old backups.
Below I call a php file with shell script and it injects processed data into related database in mysql .

Current process gives below output:
http://127.0.0.1/vod-www/Top Gun 1986.mkv

But I wish to have get:
http://127.0.0.1/vod-www/TopGun.mkv

I am starting to explain... A bit big file, I am sorry...
I have run.sh, imdb.class.php, inject.php and list_of_movies.txt file

./run.sh

run.sh
Code:
while read -r line;do
php 44.php $line
sleep 2
done<list_of_movies.txt

list_of_movies.txt
Code:
TopGun.mkv

44.php
Code:
<?php
include_once 'imdb.class.php';
//mysql config.
$servername = "127.0.0.1";
$username   = "root";
$password   = "my_password";
$dbname     = "stalker_db";
$dbport     = "3306";

//open mysql connection.
$conn = new mysqli($servername, $username, $password, $dbname, $dbport);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

//read video database to array.
$sql = mysqli_query($conn, "select * from video ORDER BY name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
    $video[] = $row;
}
#################################################################
#        $aTests = [
#                    '$argv',
#                ];
#################################################################
//grab info from imdb.
$i = 1 ;
#foreach ($aTests as $sMovie) { #--------!!!
foreach($argv as $sMovie) {
   $i++;
   $IMDB = new IMDB($sMovie);
if ($IMDB->isReady) {
$title = $IMDB->getTitle($bForceLocal = true);
$description = mysqli_real_escape_string($conn, $IMDB->getDescription());
$plot = mysqli_real_escape_string($conn, $IMDB->getPlot($iLimit = 0));
..
..
..#to make it shorter, had to delete other lines###
if (!isset($last_id)) {
$adddate = date('y-m-d H:i:s');
$sql = "INSERT INTO video (name, o_name, cost, time, protocol, category_id, cat_genre_id_1, accessed, status, description, director, country, year, actors, added, rating_kinopoisk, rating_mpaa)
VALUES ('$title $year', '$title $year', '0', '$runtime', '', '2030', '459', '1', '1', '$description',  '$director', '$country', '$year', '$cast', '$adddate', '$rating', '$mpaa')";
if ($conn->query($sql) !== TRUE) {
    echo '<p style="text-align: center;">Error: ' . $sql . '<br>' . $conn->error . '</p>';
} else {
$last_id = $conn->insert_id;
}

//get next id for screenshots table.
$sql = mysqli_query($conn, "SHOW TABLE STATUS LIKE 'screenshots'");
$next_screenshot =  mysqli_fetch_assoc($sql)['Auto_increment'];

//now we will add poster to movie.
$screenshot_file = $next_screenshot . '.jpeg';
if (!copy("/root/$poster", "/var/www/stalker_portal/screenshots/136/$screenshot_file")) {
    echo "failed to copy $screenshot_file...\n";
}
$sql = "INSERT INTO screenshots (name, type, media_id)
VALUES ('$screenshot_file', 'image/jpeg', '$last_id')";
if ($conn->query($sql) !== TRUE) {
    echo '<p style="text-align: center;">Error: ' . $sql . '<br>' . $conn->error . '</p>';
}

//add file under movie directory.
$url = 'http://127.0.0.1/vod-www/'.$title.'.'.$year.'.mkv';
..
..
#then insert into sql commands follow....
$result = mysqli_query($conn, "SELECT * FROM video_series_files WHERE url='$url'");


The problem is related to this field:
Code:
//add file under movie directory.
$url = 'http://127.0.0.1/vod-www/'.$title.'.'.$year.'.mkv';

The data injected into mysql table is:
http://127.0.0.1/vod-www/Top Gun 1986.mkv

But I wish to have get:
http://127.0.0.1/vod-www/TopGun.mkv

I replaced:
$url = 'http://127.0.0.1/vod-www/'.$title.'.'.$year.'.mkv';
by
$url = 'http://127.0.0.1/vod-www/'$xargv'.';
but did not work. Also tried different variations but no luck.
I have checked my previous posts and I do not remember how I solved it earlier.

Thank you
Boris


Solved now:
I assumed that I should create a variable for filename but have just seen that a variable for that purpose was already created earlier in code..
$url = 'http://127.0.0.1/vod-www/'.$sMovie.'.mkv';
Solved the problem Smilie


Kind regards
Boris

Last edited by baris35; 3 Weeks Ago at 07:31 AM..
This User Gave Thanks to baris35 For This Post:
# 2  
Seems a bit strange and "messy" to me to use a shell script to call a PHP file in a loop.

The first think I would do is to make it a 100% PHP script and move the loop into your PHP program and read the command line arguments using PHP.

That is a cleaner way to program.
This User Gave Thanks to Neo For This Post:
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Using PHP , call a sql inside a unix script
madfox
I am running the xampp on WINDOWS, and my php script is connecting to a unix script on a different server (ssh2_connect("11.31.138.56", 22). I am running the unix script and inside this script I am calling the .sql file . The SQL is connecting to oracle db on the unix server. But the sqlplus...... UNIX for Advanced & Expert Users
2
UNIX for Advanced & Expert Users
diffrence between method call and function call in perl
Zaxon
Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print...... Infrastructure Monitoring
4
Infrastructure Monitoring
Call shell script from php not run ?
raccsdl
Hi. I write a shell script for import data to oracle using sql loader. I set permission 755 or 777 for that script. I can run that script in the consol okay. When I call it from PHP using system command. I got return value 126 this value when don't have permission right ? I check step...... Shell Programming and Scripting
2
Shell Programming and Scripting
how to differentiate system call from library call
muru
Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru... UNIX for Advanced & Expert Users
2
UNIX for Advanced & Expert Users