inviare dati ottenuti da "parse script"

fabio_198

Utente Attivo
8 Nov 2012
53
0
0
Salve ragazzi!

Quello che non sto riuscendo proprio a fare è di inviare dei dati di una form ottentuti tramite questo script

::link errato eliminato [era: http:// www . redsunsoft.com/2011/01/p...jquery-and-php/ ]

praticamente mi invia solo l'url che appunto è un input text

gli altri dati, come l'immagine, titolo e descrizione non le invia perchè sono dentro dei <label id>

qualcuno sa come riesco a inviare il contenuto dentro i <label>'?


grazie
 
Ultima modifica di un moderatore:

criric

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
21 Ago 2010
5.607
54
48
TN
ciao
l'indirizzo è sbagliato (lo elimino)
posta il codice che hai scritto tu
 

fabio_198

Utente Attivo
8 Nov 2012
53
0
0
ok scusate

questa sarebbe la index dove c'e il form

Codice:
<?php 
	include 'db.php';
?>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<style>
	#atc_bar{width:500px;}
	#attach_content{border:1px solid #ccc;padding:10px;margin-top:10px;}
	#atc_images {width:100px;height:120px;overflow:hidden;float:left;}
	#atc_info {width:350px;float:left;height:100px;text-align:left; padding:10px;}
	#titolo {font-size:14px;display:block;}
	#atc_url {font-size:10px;display:block;}
	#atc_desc {font-size:12px;}
	#atc_total_image_nav{float:left;padding-left:20px}
	#atc_total_images_info{float:left;padding:4px 10px;font-size:12px;}
</style>
<br /><br /><br /><br />

<div align="center">
	<form method='post' action='submitadmin.php' id='formregistrazione' enctype='multipart/form-data'>
	<div id="atc_bar" align="center">
		Paste Link Here: <input type="text" name="url" size="40" id="url" />
		<input type="button" name="attach" value="Parse" id="attach" />

		
		<div id="loader">
	
			<div align="center" id="atc_loading" style="display:none"><img src="img/loading.gif" alt="Loading" /></div>
			<div id="attach_content" style="display:none">
				<div id="atc_images"></div>
				<input type="hidden" name="cur_image" value="#atc_images" id="img" />
				<div id="atc_info">
				 
				 
				 
				 
					<label id="titolo"></label>
					<label id="atc_url"></label>
					<br clear="all" />
					<label id="atc_desc"></label>
					<br clear="all" />
				</div>
				<div id="atc_total_image_nav" >
					<a href="#" id="prev"><img src="prev.png"  alt="Prev" border="0" /></a><a href="#" id="next"><img src="next.png" alt="Next" border="0" /></a>
				</div>
			 
				<div id="atc_total_images_info" >
					Showing <span id="cur_image_num">1</span> of <span id="atc_total_images">1</span> images
				</div>
				<br clear="all" />
			</div>
		</div>
		<br clear="all" />
	</div>
	<div class='controls'>
					    <button type='submit' class='btn btn-large' name='invia' id='registrati' value='Registrati'>
						Invia articolo!
					    </button>
				        </div>
	</form>
</div>


<script>

	$(document).ready(function(){	
 
		// delete event
		$('#attach').bind("click", parse_link);
		
		function parse_link ()
		{
			if(!isValidURL($('#url').val()))
			{
				alert('Please enter a valid url.');
				return false;
			}
			else
			{
				$('#atc_loading').show();
				$('#atc_url').html($('#url').val());
				$.post("fetch.php?url="+escape($('#url').val()), {}, function(response){
					
					//Set Content
					$('#titolo').html(response.title);
					$('#atc_desc').html(response.description);
					$('#atc_total_images').html(response.total_images);
					
					$('#atc_images').html(' ');
					$.each(response.images, function (a, b)
					{
						$('#atc_images').append('<img src="'+b.img+'" width="100" id="'+(a+1)+'">');
					});
					$('#atc_images img').hide();
					
					//Flip Viewable Content 
					$('#attach_content').fadeIn('slow');
					$('#atc_loading').hide();
					
					//Show first image
					$('img#1').fadeIn();
					$('#cur_image').val(1);
					$('#cur_image_num').html(1);
					
					// next image
					$('#next').unbind('click');
					$('#next').bind("click", function(){
					 
						var total_images = parseInt($('#atc_total_images').html());			 
						if (total_images > 0)
						{
							var index = $('#cur_image').val();
							$('img#'+index).hide();
							if(index < total_images)
							{
								new_index = parseInt(index)+parseInt(1);
							}
							else
							{
								new_index = 1;
							}
							
							$('#cur_image').val(new_index);
							$('#cur_image_num').html(new_index);
							$('img#'+new_index).show();
						}
					});	
					
					// prev image
					$('#prev').unbind('click');
					$('#prev').bind("click", function(){
					 
						var total_images = parseInt($('#atc_total_images').html());				 
						if (total_images > 0)
						{
							var index = $('#cur_image').val();
							$('img#'+index).hide();
							if(index > 1)
							{
								new_index = parseInt(index)-parseInt(1);;
							}
							else
							{
								new_index = total_images;
							}
							
							$('#cur_image').val(new_index);
							$('#cur_image_num').html(new_index);
							$('img#'+new_index).show();
					 	}
					});	
				});
			}
		};	
	});

	function isValidURL(url)
	{
		var RegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
		
		if(RegExp.test(url)){
			return true;
		}else{
			return false;
		}
	}
</script>

e questa è la fetch.php

Codice:
<?php 
error_reporting(E_ALL  & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 0);

$url = urldecode($_REQUEST['url']);
$url = checkValues($url);
$return_array = array();

$base_url = substr($url,0, strpos($url, "/",8));
$relative_url = substr($url,0, strrpos($url, "/")+1);

// Get Data
$cc = new cURL();
$string = $cc->get($url);
$string = str_replace(array("\n","\r","\t",'</span>','</div>'), '', $string);

$string = preg_replace('/(<(div|span)\s[^>]+\s?>)/',  '', $string);
if (mb_detect_encoding($string, "UTF-8") != "UTF-8") 
	$string = utf8_encode($string);


// Parse Title
$nodes = extract_tags( $string, 'title' );
$return_array['title'] = trim($nodes[0]['contents']);

// Parse Base
$base_override = false; 
$base_regex = '/<base[^>]*'.'href=[\"|\'](.*)[\"|\']/Ui';
preg_match_all($base_regex, $string, $base_match, PREG_PATTERN_ORDER);
if(strlen($base_match[1][0]) > 0)
{
	$base_url = $base_match[1][0];
	$base_override = true; 
}

// Parse Description
$return_array['description'] = '';
$nodes = extract_tags( $string, 'meta' );
foreach($nodes as $node)
{
	if (strtolower($node['attributes']['name']) == 'description')
		$return_array['description'] = trim($node['attributes']['content']);
}

// Parse Images
$images_array = extract_tags( $string, 'img' );
$images = array();
for ($i=0;$i<=sizeof($images_array);$i++)
{
	$img = trim(@$images_array[$i]['attributes']['src']);
	$width = preg_replace("/[^0-9.]/", '', $images_array[$i]['attributes']['width']);
	$height = preg_replace("/[^0-9.]/", '', $images_array[$i]['attributes']['height']);
	
	$ext = trim(pathinfo($img, PATHINFO_EXTENSION));
	
	if($img && $ext != 'gif') 
	{
		if (substr($img,0,7) == 'http://')
			;
		else	if (substr($img,0,1) == '/' || $base_override)
			$img = $base_url . $img;
		else 
			$img = $relative_url . $img;
		
		if ($width == '' && $height == '')
		{
			$details = @getimagesize($img);
			
			if(is_array($details))
			{
				list($width, $height, $type, $attr) = $details;
			} 
		}
		$width = intval($width);
		$height = intval($height);
		
		
		if ($width > 199 || $height > 199 )
		{
			if (
				(($width > 0 && $height > 0 && (($width / $height) < 3) && (($width / $height) > .2)) 
					|| ($width > 0 && $height == 0 && $width < 700) 
					|| ($width == 0 && $height > 0 && $height < 700)
				) 
				&& strpos($img, 'logo') === false )
			{
				$images[] = array("img" => $img, "width" => $width, "height" => $height, 'area' =>  ($width * $height),'offset' => $images_array[$i]['offset']);
			}
		}
		
	}
}
$return_array['images'] = array_values(($images));
$return_array['total_images'] = count($return_array['images']); 

header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');

echo json_encode($return_array);
exit;


/**
 * FUNCTIONS
 * Feel Free to put these in another file
 */


function sort_array_by_field($original,$field,$descending = false)
{
	$sortArr = array();
	
	foreach ( $original as $key => $value )
	{
		$sortArr[ $key ] = $value[ $field ];
	}

	if ( $descending )
	{
		arsort( $sortArr );
	}
	else
	{
		asort( $sortArr );
	}
	
	$resultArr = array();
	foreach ( $sortArr as $key => $value )
	{
		$resultArr[ $key ] = $original[ $key ];
	}

	return $resultArr;
}  


function checkValues($value)
{
	$value = trim($value);
	if (get_magic_quotes_gpc())
	{
		$value = stripslashes($value);
	}
	$value = strtr($value, array_flip(get_html_translation_table(HTML_ENTITIES)));
	$value = strip_tags($value);
	$value = htmlspecialchars($value);
	return $value;
}


function extract_tags( $html, $tag, $selfclosing = null, $return_the_entire_tag = false, $charset = 'ISO-8859-1' ){
 
	if ( is_array($tag) ){
		$tag = implode('|', $tag);
	}
 
	//If the user didn't specify if $tag is a self-closing tag we try to auto-detect it
	//by checking against a list of known self-closing tags.
	$selfclosing_tags = array( 'area', 'base', 'basefont', 'br', 'hr', 'input', 'img', 'link', 'meta', 'col', 'param' );
	if ( is_null($selfclosing) ){
		$selfclosing = in_array( $tag, $selfclosing_tags );
	}
 
	//The regexp is different for normal and self-closing tags because I can't figure out 
	//how to make a sufficiently robust unified one.
	if ( $selfclosing ){
		$tag_pattern = 
			'@<(?P<tag>'.$tag.')			# <tag
			(?P<attributes>\s[^>]+)?		# attributes, if any
			\s*/?>					# /> or just >, being lenient here 
			@xsi';
	} else {
		$tag_pattern = 
			'@<(?P<tag>'.$tag.')			# <tag
			(?P<attributes>\s[^>]+)?		# attributes, if any
			\s*>					# >
			(?P<contents>.*?)			# tag contents
			</(?P=tag)>				# the closing </tag>
			@xsi';
	}
 
	$attribute_pattern = 
		'@
		(?P<name>\w+)							# attribute name
		\s*=\s*
		(
			(?P<quote>[\"\'])(?P<value_quoted>.*?)(?P=quote)	# a quoted value
			|							# or
			(?P<value_unquoted>[^\s"\']+?)(?:\s+|$)			# an unquoted value (terminated by whitespace or EOF) 
		)
		@xsi';
 
	//Find all tags 
	if ( !preg_match_all($tag_pattern, $html, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE ) ){
		//Return an empty array if we didn't find anything
		return array();
	}
 
	$tags = array();
	foreach ($matches as $match){
 
		//Parse tag attributes, if any
		$attributes = array();
		if ( !empty($match['attributes'][0]) ){ 
 
			if ( preg_match_all( $attribute_pattern, $match['attributes'][0], $attribute_data, PREG_SET_ORDER ) ){
				//Turn the attribute data into a name->value array
				foreach($attribute_data as $attr){
					if( !empty($attr['value_quoted']) ){
						$value = $attr['value_quoted'];
					} else if( !empty($attr['value_unquoted']) ){
						$value = $attr['value_unquoted'];
					} else {
						$value = '';
					}
 
					//Passing the value through html_entity_decode is handy when you want
					//to extract link URLs or something like that. You might want to remove
					//or modify this call if it doesn't fit your situation.
					$value = html_entity_decode( $value, ENT_QUOTES, $charset );
 
					$attributes[$attr['name']] = $value;
				}
			}
 
		}
 
		$tag = array(
			'tag_name' => $match['tag'][0],
			'offset' => $match[0][1], 
			'contents' => !empty($match['contents'])?$match['contents'][0]:'', //empty for self-closing tags
			'attributes' => $attributes, 
		);
		if ( $return_the_entire_tag ){
			$tag['full_tag'] = $match[0][0]; 			
		}
 
		$tags[] = $tag;
	}
 
	return $tags;
}




class cURL
{

	var $headers;

	var $user_agent;

	var $compression;

	var $cookie_file;

	var $proxy;

	function cURL($cookies = TRUE, $cookie = 'tmp/cookies.txt', $compression = 'gzip', $proxy = '')
	{
		$this->headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg';
		$this->headers[] = 'Connection: Keep-Alive';
		$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
		$this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
		$this->compression = $compression;
		$this->proxy = $proxy;
		$this->cookies = $cookies;
		if ($this->cookies == TRUE)
			$this->cookie($cookie);
	}

	function cookie($cookie_file)
	{
		if (file_exists($cookie_file))
		{
			$this->cookie_file = $cookie_file;
		}
		else
		{
			fopen($cookie_file, 'w') or $this->error('The cookie file could not be opened. Make sure this directory has the correct permissions');
			$this->cookie_file = $cookie_file;
			fclose($this->cookie_file);
		}
	}

	function get($url)
	{
		$url = str_replace("&amp;", '&', $url);

		$process = curl_init($url);
		curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
		curl_setopt($process, CURLOPT_HEADER, 0);
		curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
		if ($this->cookies == TRUE)
			curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
		if ($this->cookies == TRUE)
			curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
		curl_setopt($process, CURLOPT_ENCODING, $this->compression);
		curl_setopt($process, CURLOPT_TIMEOUT, 30);
		curl_setopt($process, CURLOPT_HTTPGET, true);
		
		
		if ($this->proxy)
			curl_setopt($process, CURLOPT_PROXY, $this->proxy);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
		$return = curl_exec($process);
		curl_close($process);
		return $return;
	}

	function post($url, $data)
	{
		$process = curl_init($url);
		curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
		curl_setopt($process, CURLOPT_HEADER, 1);
		curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
		if ($this->cookies == TRUE)
			curl_setopt($process, CURLOPT_COOKIEFILE, $this->cookie_file);
		if ($this->cookies == TRUE)
			curl_setopt($process, CURLOPT_COOKIEJAR, $this->cookie_file);
		curl_setopt($process, CURLOPT_ENCODING, $this->compression);
		curl_setopt($process, CURLOPT_TIMEOUT, 30);
		if ($this->proxy)
			curl_setopt($process, CURLOPT_PROXY, $this->proxy);
		curl_setopt($process, CURLOPT_POSTFIELDS, $data);
		curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
		curl_setopt($process, CURLOPT_POST, 1);
		$return = curl_exec($process);
		curl_close($process);
		return $return;
	}

	function error($error)
	{
		die;
	}
}


?>

ed infine questa è la submitadmin.php che sarebbe la pagina che riceve i dati (url, titolo, descrizione, immagine) e di conseguenza dovrebbe inviarli alla tabella nel db

Codice:
<?php	
        if(!isset($_SESSION['utente'])){
          exit('non puoi accedere');
        }else{ 	
	  

	 
	   if (isset ($_POST['invia']) ) {
		
		$url = $_POST['url'];
		$img = $_POST['img'];
		$titolo = mysql_real_escape_string($_POST['titolo']);
		$descr = mysql_real_escape_string($_POST['descr']);
		$descr2 = mysql_real_escape_string($titolo);
		$fonte = $_POST['fonte'];
		$utentelog = $_SESSION['utente'];
		$categorialink = $_POST['categoria'];
				
		if($url == "" ||  $titolo == ""){
			echo "<div class='alert alert-error'>
                                <button type='button' class='close' data-dismiss='alert'>×</button>
                                <strong>Campi richiesti mancanti!</strong>
                              </div>";
			      header("Refresh: 1; URL= submitadmin.php");	
		} else {
		$result = mysql_query("INSERT INTO `my_imagelink`.`link` (url, img, titolo, descr, fonte, utentiid, categoria) VALUES ('$url', '$img', '$titolo', '$descr', '$fonte', '$utentelog', '$categorialink')");
                $result2 = mysql_query("INSERT INTO `my_imagelink`.`posts` (descr2) VALUES ('$descr2') ");

		                
		echo "<div class='alert alert-success'>
                        <button type='button' class='close' data-dismiss='alert'>×</button>
                        <strong>Articolo inviato!</strong>
                      </div>";
		      header("Refresh: 2; URL= submitadmin.php");
		}	
	   }
        }
	
?>

non riesco a trasferire sti benedetti dati :crying:
 

fabio_198

Utente Attivo
8 Nov 2012
53
0
0
praticamente ragazzi sarei arrivato alla conclusione di passare i contenuti tramite input hidden

ho questi due campi...div e input

PHP:
<div id="atc_images"></div>
<input type="hidden" name="cur_image" value="#atc_images" id="img" />

come faccio a dichiarare in VALUE di input quello che c'e dentro il DIV atc_images?

mettiamo il caso è
PHP:
<div id="atc_images">[B]ciao sono pippo[/B]</div>

VALUE dovrà essere in automatico "ciao sono pippo"

ho già provato così come vedete cioè ==> value="#atc_images"

ma appunto nel campo img del db, va a inserire proprio #atc_images
 

fabio_198

Utente Attivo
8 Nov 2012
53
0
0
soluzione trovata...ho risolto così

PHP:
<div id="atc_images"></div>
<textarea id="img" style="display:none" rows="30" cols="30" name="cur_image"></textarea> 

<input name="invia" type="submit" value="Invia" onclick="document.getElementById('img').innerHTML = getElementById('atc_images').innerHTML";>

e sul db mi copia esattamente il contenuto che viene generato dentro il div "atc_images" quindi funziona...al tal proposito vorrei sapere come "filtrare" il link dell'immagine

mi spiego...questo è il codice che viene generato dentro il div
PHP:
<img style="display: inline;" src="http://news.bbcimg.co.uk/media/images/65348000/jpg/_65348094_belreuters.jpg" id="1" width="100"><img style="display: none;" src="http://news.bbcimg.co.uk/media/images/65356000/jpg/_65356067_65356066.jpg" id="2" width="100"><img style="display: none;" src="http://news.bbcimg.co.uk/media/images/65367000/jpg/_65367308_coffee.jpg" id="3" width="100"><img style="display: inline;" src="http://news.bbcimg.co.uk/media/images/65376000/jpg/_65376729_heart.jpg" id="4" width="100">

come potete vedere c'e tutto, a me serve solo prendere il CONTENUTO di SRC dell'id 1...perchè si vede chiaramente che ci sono altre immagini con i seguenti id

in poche parole filtrandolo andrò ad avere nel campo del db il solo link dell'immagine

poi avrei anche un'altra richiesta...come faccio a fare più getElementById ??

con questo ho passato l'immagine:
PHP:
document.getElementById('img').innerHTML = getElementById('atc_images').innerHTML

dovrei passare anche il titolo che viene generato...come faccio a inserire un altro getElementById sempre nel pulsante?
 
Discussioni simili
Autore Titolo Forum Risposte Data
M Inviare dati nel db dopo risposta alert PHP 0
L inviare i dati di un form ad un database PHP 6
O [PHP] inviare dati da form e script ajax PHP 0
H [PHP] Inviare dati PHP 3
I Inviare dati POST tramite curl PHP 0
danjde inviare dati testuali verso iframe PHP 5
N inviare dati post tramite redirect PHP 4
M link con dati estratti da un db e aggiungere a tali link variabili da inviare a nuova pagina PHP 2
ciccio1892 Select concatenate con Ajax inviare scelta utente tramite post insieme ad altri dati form PHP 3
M Inviare dati da iframe alla pagina principale Javascript 1
F Inviare dati da multi form Javascript 3
K Aiuto! inviare dati da form a database mysql MySQL 2
anthares Inviare dati da form a database PHP 14
E Estrarre dati dal DB e inviare mail PHP 10
R Inviare dati form a indirizzo email PHP 23
M file php per inviare dati form PHP 0
T Inviare dati tramite post con un BUTTON Javascript 0
S inviare dati da un form a database access Flash 0
S inviare dati a 1 indirizzo email Classic ASP 1
J inviare dati via email Javascript 2
B Inviare dati ad una pagina.aspx con Javascript Javascript 1
G inviare email contenete dati da db Classic ASP 1
csi Inviare file jpg in locale alla stampante con php PHP 0
M Inviare un file su un server remoto con JavaScript Javascript 0
E Inviare variabile a PHP da ciclo in JS Javascript 0
D INVIARE PAGINA XHTML TRAMITE EMAIL HTML e CSS 1
D [HTML] Inviare un link contenente un' immagine HTML e CSS 4
M Inviare variabili da menu a tendina a pagina php con post PHP 6
I [PHP] inviare form con allegato tramite una mail PHP 1
I Guida/Tutorial configurare PHPMailer per inviare mails tramite contact form? PHP 2
A [PHP] Inviare mail con piu immagini allegate PHP 6
C non riesco a inviare la posta con account alice Posta Elettronica 1
F [Javascript] Inviare i campi di un form col metodo post Javascript 7
L [Javascript] aiuto non riesco a inviare in get dal server web locale su altervista con httpRequest Javascript 0
A Non riesco ad inviare una mail attraverso PHP su Xampp PHP 2
L 120 SMS Gratis da inviare in qualsiasi momento Vendere e Acquistare pubblicita' online 0
angelo85 Sito joomla che permetta agli utenti di inviare mail Joomla 2
E [PHP] inviare 2 form consecutivamente PHP 4
S PHP: inviare via email contenuto di una funzione PHP 4
M Come inviare due mail diverse con phpmailer PHP 6
A Creare da form un PDF da inviare come allegato. PHP 1
M Inviare mail con PHP tramite Mozilla PHP 3
M Inviare mail dopo due giorni lavorativi PHP 3
P Creare form e inviare via mail HTML e CSS 2
M Inviare mail con href PHP 2
max_400 Si possono inviare sms con php? PHP 3
S inviare the_title() in una mail tramite form html/php PHP 0
M inviare email con access MS Access 3
Shyson Inviare css con form email PHP 1
N inviare input dinamici senza ricaricare la pagina Javascript 4

Discussioni simili