Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Rodrigo Tschope

Upload AJAX + PHP com Registro MySQL

Recommended Posts

Galera seguinte, eu achei uma ferramenta muito boa pra monitorar meu up load. Só que estou com um serio problema, preciso inserir o Upload no MySQL para depois realizar uma consulta.

 

O sistema de Upload que usei foi esse :

 

http://digitarald.de/project/fancyupload/

 

A Demo:

 

http://digitarald.de/playground/uplooad.html

 

Eh bem interessante seu sistema... mas tentei varias formas para conseguir um registro no MySQL e nada... Abraços aqueles q terem e agradeço desde já a atenção de todos.. valeus!!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não não, esse script eu sei e já usei, só que assim, esses links que eu passei de um tipo de upload é bem bacana, ao final do up, ele chama um arquivo upload q faz a mudança de tmp para a pasta desejada, só q, nao registra no banco de dados, e nao eh isso que eu quero, eu quero registrar cada download. Da uma olha do programa se possivel Valeu... Eh bem complexo o treco

Compartilhar este post


Link para o post
Compartilhar em outros sites

Adailton.. olhei lah e tive as mesma ideia de um arquivo de up q tinha feito.. Adptei pra cá e pra lah mas nao vai o arquivo e nao registra no banco... vai ai meu script...

 

index.tml

<script type="text/javascript" src="core.js"></script>	<script type="text/javascript" src="Swiff.Base.js"></script>	<script type="text/javascript" src="Swiff.Uploader.js"></script>	<script type="text/javascript" src="FancyUpload.js"></script>	<style type="text/css">		/**		 * You don't need this css part, scroll down;)		 */		.halfsize		{			width:					48%;			margin-right:			5px;			float:					left;		}		form fieldset		{			border:					none;			border-top:				1px solid #888;			margin:					1em 0.5em 1em 0;			padding:				1em 0;		}		form legend		{			font-weight:			bold;			font-size:				1.2em;			color:					#888;			margin:					auto;			margin-left:			0;			padding:				0 .25em 0 0;		}		label		{			width:					10em;			float:					left;			padding:				.2em .8em 0 0;			margin-right:			.4em;			text-align:				right;			font-size:				1.1em;		}		label.error		{			color:					#ff0000;		}		label span		{			display:				block;			color:					#888;			font-size:				0.85em;			margin-bottom:			0.5em;		}		form div.label,		form div.note,		form div.footer		{			clear:					both;			margin:					1em 0 0 0;			padding:				0.1em 0.3em;		}		form div.note		{			margin-left:			.5em;		}		input,		button,		select		{			width:					10em;		}		input.submit		{			font-weight:			bold;			color:					#333;			width:					auto;			padding-right:			6px;			padding-left:			6px;		}		/**		 * Thats the basic css needed for the upload bars		 */		.photoupload-queue		{			list-style:				none;		}		.photoupload-queue li		{			background:				url(images/photo_upload.png) no-repeat 0 5px;			padding:				5px 0 5px 22px;		}		.photoupload-queue .queue-file		{			font-weight:			bold;		}		.photoupload-queue .queue-size		{			color:					#aaa;			margin-left:			1em;			font-size:				0.9em;		}		.photoupload-queue .queue-loader		{			position:				relative;			margin:					3px 15px;			font-size:				0.9em;			background-color:		#ddd;			color:					#fff;			border:					1px inset #ddd;		}		.photoupload-queue .queue-subloader		{			text-align:				center;			position:				absolute;			background-color:		#81B466;			height:					100%;			width:					0%;			left:					0;			top:					0;		}		.photoupload-queue .input-delete		{			width:					16px;			height:					16px;			background:				url(images/delete.png) no-repeat 0 0;			text-decoration:		none;			border:					none;			float:					right;		}	#top {	float: none;	height: auto;	width: auto;}	</style>	<script type="text/javascript">//<![CDATA[		/**		 * Sample Data		 */		window.addEvent('load', function()		{			/**			 * We take the first input with this class we can find ...			 */			var input = $('photoupload-filedata-1');			/**			 * Simple and easy			 * 			 * swf: the path to the swf			 * container: the object is embedded in this container (default: document.body)			 * 			 * NOTE: container is only used for the first uploader u create, all others depend			 * on the same swf in that container, so the container option for the other uploaders			 * will be ignored.			 * 			 */			var uplooad = new FancyUpload(input, {				swf: 'Swiff.Uploader.swf',				queueList: 'photoupload-queue',				container: $E('h1')			});			/**			 * We create the clear-queue link on-demand, since we don't know if the user has flash/javascript.			 * 			 * You can also create the complete xhtml structure thats needed for the queue here, to be sure			 * that its only in the document when the user has flash enabled.			 */			$('photoupload-status').adopt(new Element('a', {				href: 'java script:void(null);',				events: {					click: uplooad.clearList.bind(uplooad, [false])				}			}).setHTML('Clear Completed'));			/**			 * Second, this one uses the already injected swf embed to upload files.			 */			var uplooad2 = new FancyUpload($('photoupload2-filedata-1'), {				swf: 'Swiff.Uploader.swf',				queueList: 'photoupload-queue-2'			});		});		//]]>function MM_openBrWindow(theURL,winName,features) { //v2.0  window.open(theURL,winName,features);}</script></head><body>	<div id="container">	  <form action="teste.php" method="post" enctype="multipart/form-data" target="_blank" id="photoupload">  <div class="halfsize">	<fieldset>					<legend>Select Files</legend>					<div class="note">						Photos will be uploaded in a queue, upload them with one click.<br />						Selected Options: <b>Filetype Only Images, select multiple files, <i>upload queued</i></b>.					</div>					<div class="label emph">						<label for="photoupload-filedata-1">							Upload Photos:							<span>After selecting the photos start the upload.</span>						</label>						<input type="file" name="Filedata" id="photoupload-filedata-1" />					</div>				</fieldset>		</div>			<div class="halfsize">				<fieldset>					<legend>Upload Queue</legend>					<div class="note" id="photoupload-status">						Check the selected files and start uploading.					</div>					<ul class="photoupload-queue" id="photoupload-queue">						<li style="display: none" />					</ul>				</fieldset>			</div>			<div class="clear"></div>			<div class="footer">				<input name="Submit" type="submit" class="submit" onclick="MM_openBrWindow('teste.php','teste','status=yes,width=500,height=500')"/>			</div>	  </form></div>	</body></html>

 

teste.php(o arquivo de UPload q o Form puxa)

 

<?	if ($_FILES['Filedata']['name'] && ($log = fopen('./upload.log', 'a') ) )	{		$file = $_FILES['Filedata']['tmp_name'];		$error = false;		/**		 * THESE ERROR CHECKS ARE JUST EXAMPLES HOW TO USE THE REPONSE HEADERS		 * TO SEND THE STATUS OF THE UPLOAD, change them!		 *		 */		if (!is_uploaded_file($file) || ($_FILES['Filedata']['size'] > 2 * 1024 * 1024) )		{			$error = '400 Bad Request';		}		if (!$error && !($size = @getimagesize($file)))		{			$error = '409 Conflict';		}		if (!$error && !in_array($size[2], array(1, 2, 3, 7, 8) ) )		{			$error = '415 Unsupported Media Type';		}		if (!$error && ($size[0] < 25) || ($size[1] < 25))		{			$error = '417 Expectation Failed';		}		/**		 * This simply writes a log entry		 */		fputs($log, ($error ? 'FAILED' : 'SUCCESS') . ' - ' . gethostbyaddr($_SERVER['REMOTE_ADDR']) . ": {$_FILES[Filedata][name]} - {$_FILES[Filedata][size]} byte \n" );		fclose($log);		if ($error)		{			/**			 * ERROR DURING UPLOAD, one of the validators failed			 * 			 * see FancyUpload.js - onError for header handling			 */			header('HTTP/1.0 ' . $error);			die('Error ' . $error);		}		else		{			/**			 * UPLOAD SUCCESSFULL AND VALID			 *			 * Use move_uploaded_file here to save the uploaded file in your directory			 */			  // put the file where we'd like it			  $max_size= 1000000;$i = 0;			    // Criar diretorio   @ mkdir('fotos/teste', 0777);  // Verifica se a criacao foi bem sucedida  if(!mkdir('fotos/teste', 0777))  {   	do_html_footer();  	exit;   }// Comeca a pegar os arquivos de upload  $i = 0;  while ($_FILES['Filedata']['name'][$i]&&		 $$_FILES['Filedata']['name'][$i]!='none')  {	echo '<p>Uploading '.$_FILES['Filedata']['name'][$i].' - ';	echo $_FILES['Filedata']['size'][$i].' bytes.</p>';	if ($_FILES['Filedata']['size'][$i]==0)	{	  echo 'Problem: '.$_FILES['Filedata']['name'][$i].		   ' is zero length';	  $i++;	  continue;  	}  	if ($_FILES['Filedata']['size'][$i]>$max_size)	{	  echo 'Problem: '.$_FILES['Filedata']['name'][$i].' is over '			.$max_size.' bytes';	  $i++;	  continue;  	}	// Verifica se eh um JPG	if($i>1&&!getimagesize($_FILES['Filedata']['tmp_name'][$i]))	{	  echo 'Problem: '.$_FILES['Filedata']['name'][$i].		   ' Está, ou nã é um GIF, JPG ou PNG';	  $i++;	  continue;  	}  		  $destination = "fotos/teste/"					 .$_FILES['Filedata']['name'][$i];	  $query = "UPDATE eventos SET foto_".$i++." = '".$destination."' WHERE id = $id_pasta LIMIT 1";	  $result = mysql_query($query) or die(mysql_error());	  	  	  		  	//if we are using PHP version >= 4.03	if (!is_uploaded_file($_FILES['Filedata']['tmp_name'][$i]))	{ 	  // possible file upload attack detected	  echo 'Alguma coisa aconteceu com o arquivo '		   .$_FILES['Filedata']['name'].', não teve Upload.';	  do_html_footer();	  exit;	}		move_uploaded_file($_FILES['Filedata']['tmp_name'][$i], 					   $destination);/*	// if version <= 4.02	copy ($userfile[$i], $destination);		unlink($userfile[$i]);*/		$i++;        } }		die('Upload Successfull');	}?>

Não da erro algum na execução, porem nao faz oq deveria fazer.. alguem sabe como posso melhora-lo?!

Compartilhar este post


Link para o post
Compartilhar em outros sites

Muito bom mesmo esse sistema, estava procurando por algo assim quando vi o do Flickr e andei fuçando e descobri que ele é feito com uma interação do flash com o HTML. Estou tentando implementá-lo, mas estou tendo problemas para enviar o upload para uma pasta. Já tentei de tudo, mas é como se ele não abrisse o upload.php e não faz o tratamento das requisições. Quando publico ele no servidor, ele retorna o erro 403... Se souber de algo ome fala... abraços...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Olá Rodrigo Tschope. Estou tendo o mesmo problema. O arquivo que contem os comandos php não dá os comandos no mysql. Você conseguiu resolver?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.