Jump to content
Andre025

upload PHP

Recommended Posts

Andre025

Boa tarde não sei se por acaso este tópico já foi aberto por isso peço desde já as minhas desculpas.

O que se passa é o seguinte:

Estou a desenvolver um site em PHP/HTLM e tenho de fazer um upload e para isso usei um função que fui buscar a este link:

http://forum.imasters.com.br/index.php?/topic/411903-upload-de-imagens-dw-cs5/

e coloquei no meu código desta maneira:

<?php require_once('Connections/gestfrota.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO equipamentos (marca, modelo, oleo, `data`, foto, manual, referencia, ano) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['marca'], "text"),
                       GetSQLValueString($_POST['modelo'], "text"),
                       GetSQLValueString($_POST['oleo'], "text"),
                       GetSQLValueString($_POST['data'], "text"),
                       GetSQLValueString($_POST['foto'], "text"),
                       GetSQLValueString($_POST['manual'], "text"),
                       GetSQLValueString($_POST['referencia'], "text"),
                       GetSQLValueString($_POST['ano'], "date"));

  mysql_select_db($database_gestfrota, $gestfrota);
  $Result1 = mysql_query($insertSQL, $gestfrota) or die(mysql_error());

  $insertGoTo = "vizual_veiculos.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--

Design by Free CSS Templates
http://www.freecsstemplates.org
Released for free under a Creative Commons Attribution 2.5 License

Title      : Emporium
Version    : 1.0
Released   : 20090222
Description: A two-column, fixed-width and lightweight template ideal for 1024x768 resolutions. Suitable for blogs and small websites.

-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Emporium by Free Css Templates</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#apDiv2 {   position:absolute;
   width:327px;
   height:67px;
   z-index:1;
   left: 216px;
   top: 61px;
}
</style>
</head>
<body>
<div id="wrapper">
<!-- start header -->
<div id="logo">
   <h1> </h1>
   <div id="apDiv2"><img src="../../../../../wamp/www/PAP/images/grupo_isidoro.gif" alt="" width="328" height="69" id="topo_logo2" />  <>
   <h2> </h2>
<>
<div id="header">
   <div id="menu">
      <ul>
         <li class="current_page_item"><a href="vizual_equipamentos.php"><<<Voltar</a></li>
      </ul>
   <>
<>
<!-- end header -->
<>
<!-- start page -->
<div id="page">
   <!-- start content --><!-- end content -->
   <!-- start sidebar --><!-- end sidebar -->
  <div style="clear: both;">  <>
  <p> </p>
  <form name="form1" action="<?php echo $editFormAction; ?>" method="POST" id="form1">
    <p>Referencia
      <label for="referencia"></label>
                  
      <input type="text" name="referencia" id="referencia" />
    </p>
    <p>Marca
      <label for="marca"></label>
                          
      <input type="text" name="marca" id="marca" />
    </p>
    <p>Modelo
      <label for="modelo"></label>
                         
      <input type="text" name="modelo" id="modelo" />
    </p>
    <p>Tipo de óleos
      <label for="oleo"></label>
               
      <input type="text" name="oleo" id="oleo" />
    </p>
    <p>Data de Aquisição
      <label for="data"></label>
      <input type="text" name="data" id="data" />
    </p>
    <p>Ano de fabrico
      <label for="ano"></label>
            
      <input type="text" name="ano" id="ano" />
    </p>
    <p>Foto                         
<label for="foto"></label>
      <input type="file" name="foto" id="foto" />
    </p>
    <p>Manual
      <label for="manual"></label>
                        
      <input type="file" name="manual" id="manual" />
    </p>
    <p> </p>
    <p>
                                                                                                                       
      <input type="submit" name="inserir" id="inserir" value="Inserir" />
    </p>
    <input type="hidden" name="MM_insert" value="form1" />
  </form>
  <p> </p>
<p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
<>
<!-- end page -->
<!-- start footer -->
<div id="footer">
   <p id="legal">Copyright © 2011 - André Lopes/ Grupo Isidoro</p>
<>
<!-- end footer -->
</body>
</html>

so que ele agora não faz o upload nem sequer manda o nome da foto para a base de dados.

Se alguem me pudesse ajudar agradecia.

Desde já o meu obrigado.

Share this post


Link to post
Share on other sites
brunoais

Aqui:

<form name="form1" action="<?php echo $editFormAction; ?>" method="POST" id="form1">

Qual é o valor da variável: $editFormAction ?

Qual é o caminho da 1ª página e da 2ª página?


"[Os jovens da actual geração]não lêem porque não envolve um telecomando que dê para mirar e atirar, não falam porque a trapalhice é rainha e o calão é rei" autor: thoga31

Life is a genetically transmitted disease, induced by sex, with death rate of 100%.

Share this post


Link to post
Share on other sites
diokhan

eu tenho um problema parecido, e para nao abrir um novo topico sobre o mesmo utilizo este.

Eu tenho um script em php para fazer o upload de 2 ficheiros, mas quando faço upload envia-me para a pagina em branco, tentei fazer um echo mas nada.

aqui fica o codigo caso alguem possa ajudar-me.

codigo onde tenho a form:

<form action='execute.php' method='POST' enctype='multipart/form-data' name="form1" id="form1">

Project Name: <input type='text' name='projName' size='95' />

<br><br>

Sequences: <textarea name='sequences' rows='15' cols='80' style='width: 100%;'></textarea>

<br><br>

File 1: <div><input name="ufile[]" type="file" /></div>

<br><br>
Reverse Sequence: <input type="checkbox" name="reverse" value="1">
<br>

File 2: <div><input name="ufile[]" type="file" /></div>
<br><br>

<center>

	<input type='submit' value='Submit'>

</center>

</form>

<br><br>
<center>
<font color=#006633>
	<strong>
		<br><p class='meta'></p>....<br>
	</strong>
</font>
</center>

codigo onde trato os dados enviados (pagina que aparece em branco apos clicar em upload)

<?php
error_reporting(E_ALL);


function run_in_background($Command, $projName){
chdir("results/".$projName."/");

$PID = shell_exec("nohup $Command 2> /dev/null & echo $!");
chdir("../..");
return $PID;

}



function countSequences($file){

$str = file_get_contents($file);
$output = substr_count($str, '>');

return $output;

}



if (isset($_POST['projName']) && $_POST['projName'] != ""){

$dir = "results/" . $_POST['projName']."/";

if (!file_exists($dir)){ mkdir($dir, 0744, true); }

if (isset($_POST['sequences']) && $_POST['sequences'] != ""){

	$myFile = "results/" . $_POST['projName']."/tempSeq.fasta";

	$fh = fopen($myFile, 'w');

	fwrite($fh, $_POST['sequences']);

	fclose($fh);

	$nSeq = countSequences($myFile);

	if ($nSeq == 2){
		$cmd = "";
		if (isset($_POST['reverse'])){
			$directory = "/var/www/html/mishima/results/" . $_POST['projName']."/";
			popen("/usr/local/bin/python /var/www/html/mishima/reverseSeq.py ".$directory." tempSeq.fasta tempSeq_rev.fasta");
			$cmd = "/home/Software/mishima/mishima -in tempSeq_rev.fasta -align-seeds-only > result.txt";
		}else{
			$cmd = "/home/Software/mishima/mishima -in tempSeq.fasta -align-seeds-only > result.txt";
		}

		$ps = run_in_background($cmd, $_POST['projName']);
		$myPID = "results/" . $_POST['projName']."/pid.txt";

		$fh2 = fopen($myPID, 'w');

		fwrite($fh2, $ps);

		fclose($fh2);

		//header ("Location: index.php?msg=3"); // running

	}else{
		$directory = "results/" . $_POST['projName']."/";
		//if (file_exists($myFile)){ system("rm " . $myFile); }
		//if (file_exists($directory)){ system("rmdir " . $directory); }
		//header ("Location: index.php?msg=2"); /* more than 2 sequences or just 1 sequnece */ 
	}

}else{

	if ($_FILES["ufile"]["size"][0] > 0){
		if ($_FILES["ufile"]["size"][1] > 0){
			$dir1 = $dir . $_FILES["ufile"]['name'][0];

			copy($_FILES["ufile"]['tmp_name'][0], $dir1); // copy upload file to directory

			$dir2 = $dir . $_FILES["ufile"]['name'][1];

			copy($_FILES["ufile"]['tmp_name'][1], $dir2); // copy upload file to directory

			$fasta1 = $dir . $_FILES["ufile"]['name'][0];
			$fasta2 = $dir . $_FILES["ufile"]['name'][1];

			$nSeq1 = countSequences($fasta1);
			// if fasta1 have 2 sequence and fasta 2 is reverse
			if($nSeq1 == 2 && isset($_POST['reverse'])){
				$directory = "/var/www/html/mishima/results/".$_POST['projName']."/";

				// return only 1 sequence in fasta 1 file
				popen("/usr/local/bin/python /var/www/html/mishima/getFirstSeq.py ".$directory." ".$_FILES["ufile"]['name'][0]." fasta1seq.fasta", "r");
				$fasta1 = $directory."fasta1seq.fasta";

				// reverse sequence in fasta 2 file
				popen("/usr/local/bin/python /var/www/html/mishima/reverseSeq.py ".$directory." ".$_FILES["ufile"]['name'][1]." tempSeq_rev2.fasta", "r");

				$fasta2 = $directory."tempSeq_rev2.fasta";

			// if fasta1 have 2 sequence and fasta2 is not reverse
			}elseif ($nSeq1 == 2 && !isset($_POST['reverse'])){
				$directory = "/var/www/html/mishima/results/".$_POST['projName']."/";

				// return only 1 sequence in fasta 1 file
				popen("/usr/local/bin/python /var/www/html/mishima/getFirstSeq.py ".$directory." ".$_FILES["ufile"]['name'][0]." fasta1seq.fasta", "r");
				$fasta1 = $directory."fasta1seq.fasta";

			// if fasta1 have 1 sequence
			}elseif ($nSeq1 == 1){
				// reverse sequence in fasta 2 file
				if (isset($_POST['reverse'])){
					$directory = "/var/www/html/mishima/results/".$_POST['projName']."/";
					popen("/usr/local/bin/python /var/www/html/mishima/reverseSeq.py ".$directory." ".$_FILES["ufile"]['name'][1]." tempSeq_rev2.fasta", "r");
					$fasta2 = $directory."tempSeq_rev2.fasta";
				}
			}

			system("cat ".$fasta1." ".$fasta2." > seq.fasta");
			$cmd = "/home/Software/mishima/mishima -in seq.fasta -align-seeds-only > result.txt";

			$ps = run_in_background($cmd, $_POST['projName']);
			$myPID = "results/" . $_POST['projName']."/pid.txt";

			$fh2 = fopen($myPID, 'w');

			fwrite($fh2, $ps);

			fclose($fh2);

			//header ("Location: index.php?msg=3"); // running
		}else{
			$cmd = "/home/Software/mishima/mishima -in ".$_FILES["ufile"]['name'][0]." -align-seeds-only > result.txt";

			$ps = run_in_background($cmd, $_POST['projName']);
			$myPID = "results/" . $_POST['projName']."/pid.txt";

			$fh2 = fopen($myPID, 'w');

			fwrite($fh2, $ps);

			fclose($fh2);

			//header ("Location: index.php?msg=3"); // running
		}

	}else{ 
		$directory = "results/" . $_POST['projName']."/";
		//if (file_exists($dir)){ system("rm " . $dir); }
		//if (file_exists($directory)){ system("rmdir " . $directory); }
		//header ("Location: index.php?msg=0"); /* file is empty */ 
	}

}

}else{ //header ("Location: index.php?msg=1"); /* project name is empty */ }

?>

EDIT: sei que no código php tem os header comentados, mas eu fiz isso para poder fazer os echo mas sem sucesso. E mesmo com os header sem estar comentado da-me a pagina em branco a mesma como resultado

desde já obrigado


...Join the dark side...and get a free cookie...

Share this post


Link to post
Share on other sites
diokhan

eu já reparei que se fizer o upload apenas para 1 ficheiro, retirar a linha "<div><input name="ufile[]" type="file" /></div>", manter só uma, funciona o script, mas com a segunda já nao funciona, nao passa as variaveis nem os ficheiros que quero fazer o upload.

Alguem sabe se é preciso alterar o ficheiro php.ini ou assim para fazer o upload de dois inputs na mesma form? Ou alguma forma de funcionar do modo que tenho?

🤔

EDIT: Já resolvi, só precisava de ir ao php.ini e mudar um valor, porque a soma dos dois ficheiros juntos era superior ao permitido, aumentei o valor e ja funciona bem


...Join the dark side...and get a free cookie...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.