in una pagina con un checkbox ho messo questo codice:
if (isset($_POST['img'])) {
header("location:upimage.php?tb=approf&direc=appro fondimenti");
}
nel file upimage.php utilizzo questo script:
<?php
//
// Upload Files x5 v1.0
// by Marek "TheMafia" Gozdzik themafiatr@hotmail.com
//
// The uploaded files will overwrite any files with the same name in $uploadDir as well as
// in the database Table
//
// Use the following to match your database
// $dbServer - Your SQL server(default = "localhost") [$dbuser and $dbpass corrisbonding]
// $dbDatabase - The database containing your designated table
// $dbTable - Destination table
//
// A table is needed with the following fields:
// <imageID> : primary key, auto increment
// <imageName> : Modify $dbAliasImgName to the name in your database - varchar(256)
// <imageSize> : Modify $dbAliaseImgSize to the name in your database - int(11)
//
// The upload directory is stored in $uploadDir, default is "uploadedImages"
//
//
// Variables
//
$dbServer = "xxxxxxxx";
$dbuser = "xxxxxx";
$dbpass = "xxxxx";
$dbDatabase = "xxxxxxxxx";
$dbTable = "approf";
$dbAliasImgName = "name"; //name of field for image name in your database
$dbAliasImgSize = "size"; //name of field for imagae size
$currentDir = getcwd();
$uploadDir = $_GET['direc'];
//
// Form
//
if (empty($_FILES['userfile'])) { //Fresh load, no POST ?>
<form enctype="multipart/form-data" action="upimage.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
Send this file:
Image 1: <input name="userfile[]" type="file" />
<input type="submit" value="Send File(s)" />
</form>
<?php
}
else { // If form has POST
//
// SQL Connect
//
$myConn = mysql_connect($dbServer, $dbuser, $dbpass)
or die("Fialed Connection to $dbServer; No connection to Database; ".mysql_error());
//
// SQL Adjusts & Variabless
//
mysql_select_db($dbDatabase, $myConn); //$dbDatabase in place of first column
$mySql = "";
//
// Directory Handling - Read for user & owner group, owner has all permissions
//
//echo $currentDir.$uploadDir;
mkdir($currentDir."".$uploadDir, 0744); qui mi da errore di variabile Undefined index: direc
//
// Form POST
//
foreach ($_FILES["userfile"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
//
// Uploaded File handling
//
$tmp_name = $_FILES["userfile"]["tmp_name"][$key];
$name = $_FILES["userfile"]["name"][$key];
$size = $_FILES["userfile"]["size"][$key];
move_uploaded_file($tmp_name, $currentDir.$uploadDir."/$name");
//
// SQL
//
$mySql = "SELECT COUNT($dbAliasImgName) AS result FROM $dbTable WHERE $dbAliasImgName = '" . $name. "'";
$result = mysql_query($mySql, $myConn) or die(mysql_error());
echo $result;
$mySql = "Insert into $dbTable ($dbAliasImgName, $dbAliasImgSize) values ('$name', $size)";
mysql_query($mySql, $myConn) or die(mysql_error());
}
}
mysql_close($myConn);
?>
Done uploading
<?php }
?>

Rispondi quotando
:master:

