View Full Version : [PHP] "grabbare" uno script
ciao a tutti, domanda da assoluto newbie...vorrei sapere se è possibile "grabbare" lo script contenuto in questa pagina:
http://www.myspacetops.com/models/index.php
se lo guardo con un browser ottengo direttamente un'immagine e non ho il tempo di attivare visualizza codice!
vorrei proprio questo perchè è l'unico che funziona abbinato ai css su myspace - in poche parole randomizza l'immagine di sfondo, lo abbino a body come image: url(...) - ne ho provati sino ad ora 4 ma l'unico che funziona è questo.
vorrei copiare questo script e salvarlo insieme ad altre immagini sul mio ftp per personalizzare l'effetto, ora mostra foto di modelle
grazie
:)
Non si può. Viene interpretato dal server e viene fatto un redirect sull'immagine scelta.
ciao a tutti, domanda da assoluto newbie...vorrei sapere se è possibile "grabbare" lo script contenuto in questa pagina:
http://www.myspacetops.com/models/index.php
se lo guardo con un browser ottengo direttamente un'immagine e non ho il tempo di attivare visualizza codice!
vorrei proprio questo perchè è l'unico che funziona abbinato ai css su myspace - in poche parole randomizza l'immagine di sfondo, lo abbino a body come image: url(...) - ne ho provati sino ad ora 4 ma l'unico che funziona è questo.
vorrei copiare questo script e salvarlo insieme ad altre immagini sul mio ftp per personalizzare l'effetto, ora mostra foto di modelle
grazie
:)
non è possibile...php interpreta lo script e apache (o chi per lui) visualizza solo il suo output.
scrivere un qualcosa del genere non è troppo difficile comunque.
Immaginavo...
Ora sto usando uno script che pare ottenere lo stesso risultato (ovvero un'imamgine random) ma non funziona una volta montato su myspace:
http://www.errorizm.izfree.com/bkg/random.php
l'unica differenza che noto con lo script delle modelle è che questo, come "risultato" nel browser, mi da sempre http://www.errorizm.izfree.com/bkg/random.php - ovvero l'url dello script - anzichè http://www.errorizm.izfree.com/bkg/1.jpg - ovvero l'url diretto dell'immagine pescata random. che sia questo quello che non lo fa funzionare una volta inserito come body:url()?
il codice è questo, tratto da http://www.totallyphp.co.uk/scripts/random_image.htm
<?php
/*
* Name your images 1.jpg, 2.jpg etc.
*
* Add this line to your page where you want the images to
* appear: <?php include "randomimage.php"; ?>
*/
// Change this to the total number of images in the folder
$total = "2";
// Change to the type of files to use eg. .jpg or .gif
$file_type = ".jpg";
// Change to the location of the folder containing the images
$image_folder = "../bkg/";
// You do not need to edit below this line
$start = "1";
$random = mt_rand($start, $total);
$image_name = $random . $file_type;
echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";
?>
Non funziona perché il primo funziona tramite redirect, mentre il secondo "stampa" condice HTML.
al posto di
echo "<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";
metti
$data = file_get_contents($image_folder."/".$image_name, FILE_BINARY, NULL)
if ($data != FALSE)
{
header('Content-Type: image/jpeg'); // JPG picture
echo $data;
}
come nome dell'immagine devi specificare il nome dello script
Grazie Vizzz, provo a inserire le tue modifiche!
mi restituisce questo errore:
Parse error: syntax error, unexpected T_IF in /home/matteo/domains/errorizm.izfree.com/public_html/bkg/random.php on line 28
l'ho inserito così, ho sbagliato qualcosa?
<?php
/*
* Name your images 1.jpg, 2.jpg etc.
*
* Add this line to your page where you want the images to
* appear: <?php include "randomimage.php"; ?>
*/
// Change this to the total number of images in the folder
$total = "2";
// Change to the type of files to use eg. .jpg or .gif
$file_type = ".jpg";
// Change to the location of the folder containing the images
$image_folder = "../bkg/";
// You do not need to edit below this line
$start = "1";
$random = mt_rand($start, $total);
$image_name = $random . $file_type;
$data = file_get_contents($image_folder."/".$image_name, FILE_BINARY, NULL)
if ($data != FALSE)
{
header('Content-Type: image/jpeg'); // JPG picture
echo $data;
}
?>
grazie
ops non l'ho testato...prova con FALSE scritto minuscolo
ops non l'ho testato...prova con FALSE scritto minuscolo
purtroppo mi da lo stesso errore
Parse error: syntax error, unexpected T_IF in /home/matteo/domains/errorizm.izfree.com/public_html/bkg/random.php on line 28
purtroppo mi da lo stesso errore
Parse error: syntax error, unexpected T_IF in /home/matteo/domains/errorizm.izfree.com/public_html/bkg/random.php on line 28
ho fatto il classico errore:
$data = file_get_contents($image_folder."/".$image_name, FILE_BINARY, NULL)
manca il ; finale!
Grazie mille!! Funziona perfettamente!!
Riporto il codice corretto:
<?php
/*
* Name your images 1.jpg, 2.jpg etc.
*
* Add this line to your page where you want the images to
* appear: <?php include "randomimage.php"; ?>
*/
// Change this to the total number of images in the folder
$total = "2";
// Change to the type of files to use eg. .jpg or .gif
$file_type = ".jpg";
// Change to the location of the folder containing the images
$image_folder = "../bkg/";
// You do not need to edit below this line
$start = "1";
$random = mt_rand($start, $total);
$image_name = $random . $file_type;
$data = file_get_contents($image_folder."/".$image_name, FILE_BINARY, NULL);
if ($data != false)
{
header('Content-Type: image/jpeg'); // JPG picture
echo $data;
}
?>
Il codice originale, con la spiegazione dei parametri da personalizzare è qui:
http://www.totallyphp.co.uk/scripts/random_image.htm
Si può utilizzare in un CSS:
body {
background-image:url(www.miosito.it/nomescript.php);
}
per caricare uno sfondo diverso od ogni refresh e/o caricamento della pagina. Funziona anche per i profili Myspace.
ottimo...ma ha un qualche limite questo script:
- non gestisce il caso in cui non esista il file scelto tramite random
- devi specificare manualmente il numero massimo di immagini
- devi nominare tutte le immagini con numeri progressivi
almeno per il primo punto si potrebbe migliorare così:
<?php
/*
* Name your images 1.jpg, 2.jpg etc.
*
* Add this line to your page where you want the images to
* appear: <?php include "randomimage.php"; ?>
*/
// Change this to the total number of images in the folder
$total = 2;
// Number of tries
$tries = 100;
// Change to the type of files to use eg. .jpg or .gif
$file_type = ".jpg";
// Change to the location of the folder containing the images
$image_folder = "../bkg/";
// You do not need to edit below this line
$start = 1;
$cnt = 0;
while ($cnt++ < $tries)
{
$random = mt_rand($start, $total);
$image_name = $random . $file_type;
if (!file_exists($image_folder."/".$image_name))
continue;
$data = file_get_contents($image_folder."/".$image_name, FILE_BINARY, NULL);
if ($data != false)
{
header('Content-Type: image/jpeg'); // JPG picture
echo $data;
die();
}
}
?>
Io metterei un vettore con tutte le immagini, poi con mt_rand estrarrei il nome del file dal vettore.
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.