Ola´pessoal, é o seguinte eu tenho uma área administrativa onde o usuário depois de cadastrado, pode enviar a sua foto, mas ta aí o pau... não consigo fazer o upload por nada, e nem mandar o nome da foto pro servidor... de uma olhada no meu code, por favor me ajudem..
Eu sei que tem alguma coisa errada, mas não sei alterar sou iniciante, em Php, se alguém habilitar em rescreever o codigo e explicasse qual erro, seria muito bom aproveito para mim e os outros usuários.
Tabela.sql
CREATE TABLE usuarios (
uname varchar(10) NOT NULL default '',
upass varchar(10) NOT NULL default '',
nome varchar(100) NOT NULL default '',
image varchar(100) NOT NULL default '',
PRIMARY KEY (uname)
) ENGINE=MyISAM;
Conn.php
<?
$connection = mysql_connect("localhost", "root", "")
or die (mysql_error());
$db = mysql_select_db("usuarios", $connection) or die (mysql_error());
?>
Upload.php
<?php
session_start();
if(empty($_SESSION[uname]))
{
header("location:login.php");
}
else
{
include_once "conn.php";
}
?>
<?php
$q1 = "select image from usuarios where uname = \"$uname\" ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);
?>
<html>
<head>
<title><?=$UPLOADIMG?></title>
<?
if ($REQUEST_METHOD == "POST")
{
/* SUBMITTED INFORMATION - use what you need
* temporary filename (pointer): $imgfile
* original filename : $imgfile_name
* size of uploaded file : $imgfile_size
* mime-type of uploaded file : $imgfile_type
*/
/*== upload directory where the file will be stored
relative to where script is run ==*/
$uploaddir = "images/";
/*== get file extension (fn at bottom of script) ==*/
/*== checks to see if image file, if not do not allow upload ==*/
$pext = getFileExtension($imgfile_name);
$pext = strtolower($pext);
if (($pext != "jpg") && ($pext != "jpeg") && ($pext != "gif"))
{
print "<h1>ERROR</h1>Image Extension Unknown.<br>";
print "<p>Please upload only a JPEG or GIF image with the extension .gif , .jpg or .jpeg ONLY<br><br>";
print "The file you uploaded had the following extension: $pext</p>\n";
/*== delete uploaded file ==*/
exit();
}
/*== setup final file location and name ==*/
/*== change spaces to underscores in filename ==*/
$rand_numb = md5(uniqid(microtime())); //generate random name u can change this to rand(1,99999); if u want make shorter name
$neu_name = "$rand_numb"."$imgfile_name";
$final_filename = str_replace(" ", "_", $neu_name);
$newfile = $uploaddir . "/$final_filename";
/*== do extra security check to prevent malicious abuse==*/
if (is_uploaded_file($imgfile))
{
/*== move file to proper directory ==*/
if (!copy("$imgfile","$newfile"))
{
/*== if an error occurs the file could not
be written, read or possibly does not exist ==*/
print "Error Uploading File.";
exit();
}
}
/*== delete the temporary uploaded file ==*/
echo "<br>
This is the image you upload :<br><br>
<img src='$newfile'><br>
<br>
If you want to replace it just upload another image . <br>
<br>
<center><a href=upload.php>Go Back</a></center>";
/*== DO WHATEVER ELSE YOU WANT
SUCH AS INSERT DATA INTO A DATABASE ==*/
if (is_uploaded_file($imgfile))
{
$qup = "update usuarios set image = \"$newfile\" where uname = \"$uname\" ";
$rup = mysql_query($qup) or die(mysql_error());
include "../footer.php";
exit();
}
}
?>
<p align="right"><font color="#FF6600"><strong><br>
Upload your Picture !</strong></font>
<hr size="1" color=#FF6600></p>
<?=$WARNINGUPLOAD?>
<form action="<?=$SCRIPT_NAME; ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="50000">
<p><?=$UPLOADIMG?> <input type="file" name="imgfile"><br>
<font size="1"><?=$CLICKTOUPLOAD?></font><br>
<br>
<input type="submit" value="Upload Image">
</form>
<?
/*== FUNCTIONS ==*/
function getFileExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
include_once('../footer.php');
?>
[code]
Question
leaio
Ola´pessoal, é o seguinte eu tenho uma área administrativa onde o usuário depois de cadastrado, pode enviar a sua foto, mas ta aí o pau... não consigo fazer o upload por nada, e nem mandar o nome da foto pro servidor... de uma olhada no meu code, por favor me ajudem..
Eu sei que tem alguma coisa errada, mas não sei alterar sou iniciante, em Php, se alguém habilitar em rescreever o codigo e explicasse qual erro, seria muito bom aproveito para mim e os outros usuários.
Tabela.sql
Conn.php Upload.phpLink to comment
Share on other sites
0 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.