Hallo, ik ben bezig met het maken van een upload script. Alles doet het goed. Maar op 1 of andere manier geeft die het path van mijn upload voor de foto's niet mee.
Wie kan me helpen ?
<?php
include "database/webconfig.php";
require "class/upload_class.php";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$_upload = new upload($_FILES["picture"]["name"],$_FILES["picture"]["tmp_name"],"uploads/");
$_upload->check_filesize($_FILES["picture"]["size"]);
$_upload->check_extension("jpg jpeg gif");
$_upload->check_double("1");
if ($_upload->do_upload())
print "File uploaded :-)";
else
print "Uploading failed";
}
else {
?>
<form action="<?php echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data" name="form" id="form">
<table width="510" border="0">
<tr>
<td>Nomme:</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Adresse:</td>
<td><input name="adres" type="text" id="adres"></td>
</tr>
<tr>
<td>CP:</td>
<td><input name="zipcode" type="text" id="zipcode"></td>
</tr>
<tr>
<td>Ville:</td>
<td><input name="city" type="text" id="city"></td>
</tr>
<tr>
<td>Nomme bebe:</td>
<td><input name="baby" type="text" id="baby"></td>
</tr>
<tr>
<td>Date de naissance:</td>
<td><select name="day" id="day">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select name="month" id="month">
<option>janvier</option>
<option>février</option>
<option>mars</option>
<option>avril</option>
<option>mai</option>
<option>juin</option>
<option>juillet</option>
<option>août</option>
<option>septembre</option>
<option>octobre</option>
<option>novembre</option>
<option>décembre</option>
</select>
<select name="year" id="year">
<option>2000</option>
<option>2001</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option>2006</option>
</select></td>
</tr>
<tr>
<td>Description de photo:</td>
<td><input name="description" type="text" id="description"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td>Photo upload</td>
<td><input name="picture" type="file" id="picture">
</tr>
<tr>
<td> </td>
<td><input name="uploaden" type="submit" id="uploaden" value="Submit"></td>
</tr>
</table>
</form>
<?php
}
if (true) {
if(trim($_POST['name']) <> "" && trim($_POST['adres']) <> "" && trim($_POST['zipcode']) <> "" && trim($_POST['city']) <> "" && trim($_POST['baby']) <> "" && trim($_POST['day']) <> "" && trim($_POST['month']) <> "" && trim($_POST['year']) <> "" && trim($_POST['description']) <> "" && trim($_POST['email']) <> "" ) {
$name = $_POST['name'];
$adres = $_POST['adres'];
$zipcode = $_POST['zipcode'];
$city = $_POST['city'];
$baby = $_POST['baby'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$description = $_POST['description'];
$email = $_POST['email'];
$picture = $_POST['picture'];
mysql_query
("INSERT INTO personal
(name,
adres,
zipcode,
city,
baby,
day,
month,
year,
description,
email,
picture)
VALUES
('".$name."',
'".$adres."',
'".$zipcode."',
'".$city."',
'".$baby."',
'".$day."',
'".$month."',
'".$year."',
'".$description."',
'".$email."',
'".$picture."')") or die(mysql_error());
mysql_close();
}
}
?>
Dit is mijn upload class
<?php
class upload {
var $tmp;
var $path;
var $name;
var $error="";
var $mode;
var $max_size=1024;
var $ext="jpg jpeg gif";
var $file;
var $file_ext;
function upload ($name="",$name_tmp="",$path="") {
if (empty($path))
$this->error .= "<li>The script can't work with an empty path.</li>\n";
if (empty($name) || empty($name_tmp))
$this->error .= "<li>Please select a file to upload</li>\n";
$this->tmp = $name_tmp;
$this->path = $path;
$this->name = $name;
}
function check_extension ($ext="") {
if (!empty($ext))
$this->ext = $ext;
$name = explode(".",$this->name);
$total = count($name)-1; // an array starts with 0 not 1!
$this->file_ext = strtolower($name[$total]);
$this->file = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($this->name)))); // cleanup the file
$this->file = str_replace(".".$this->file_ext,"",$this->file); // get the name without the extension
unset($total);
$ext_perm = explode(" ",$this->ext);
$valid_ext = 0;
$total = count($ext_perm);
for ($i=0; $i<$total; $i++) {
if ($this->file_ext == $ext_perm[$i]) {
$valid_ext = 1;
break;
}
}
if ($valid_ext == 0)
$this->error .= "<li>Only the following extensions will be accepted: ".$this->ext."</li>\n";
}
function check_double($mode="0") {
$this->mode = $mode;
switch ($this->mode) {
case "0": // Stop
if (file_exists($this->path.$this->file.".".$this->file_ext))
$this->error .= "<li>The filename already exists. Please rename your file.</li>\n";
$this->path = $this->path.$this->file.".".$this->file_ext;
break;
case "1": // Rename
$copy = "";
$i = 1;
while (file_exists($this->path.$this->file.$copy.".".$this->file_ext)) {
$copy = "_copy_".$i;
$i++;
}
$this->path = $this->path.$this->file.$copy.".".$this->file_ext;
break;
case "2": // Overwrite
$this->path = $this->path.$this->file.".".$this->file_ext;
break;
default:
$this->error .= "<li>The config of the upload script contains an error. Please contact the webmaster.</li>\n";
break;
}
}
function check_filesize ($file_size,$max_size="") {
if (!empty($max_size))
$this->max_size = $max_size;
$this->max_size = $this->max_size*1024;
if ($file_size >= $this->max_size)
$this->error .= "<li>The filesize (".round($file_size/1024)." kb) of your file is to big. The maximum size is: ".round($this->max_size/1024)." kb.</li>\n";
}
function do_upload () {
if (!empty($this->error)) {
print $this->error;
exit();
}
if (!@move_uploaded_file($this->tmp,$this->path)) {
@unlink($this->tmp);
return false;
}
if ($this->file_ext != "exe")
@chmod ($this->path, 0777);
return true;
}
}
?>
Wie kan me helpen ?
<?php
include "database/webconfig.php";
require "class/upload_class.php";
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$_upload = new upload($_FILES["picture"]["name"],$_FILES["picture"]["tmp_name"],"uploads/");
$_upload->check_filesize($_FILES["picture"]["size"]);
$_upload->check_extension("jpg jpeg gif");
$_upload->check_double("1");
if ($_upload->do_upload())
print "File uploaded :-)";
else
print "Uploading failed";
}
else {
?>
<form action="<?php echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data" name="form" id="form">
<table width="510" border="0">
<tr>
<td>Nomme:</td>
<td><input name="name" type="text" id="name"></td>
</tr>
<tr>
<td>Adresse:</td>
<td><input name="adres" type="text" id="adres"></td>
</tr>
<tr>
<td>CP:</td>
<td><input name="zipcode" type="text" id="zipcode"></td>
</tr>
<tr>
<td>Ville:</td>
<td><input name="city" type="text" id="city"></td>
</tr>
<tr>
<td>Nomme bebe:</td>
<td><input name="baby" type="text" id="baby"></td>
</tr>
<tr>
<td>Date de naissance:</td>
<td><select name="day" id="day">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select name="month" id="month">
<option>janvier</option>
<option>février</option>
<option>mars</option>
<option>avril</option>
<option>mai</option>
<option>juin</option>
<option>juillet</option>
<option>août</option>
<option>septembre</option>
<option>octobre</option>
<option>novembre</option>
<option>décembre</option>
</select>
<select name="year" id="year">
<option>2000</option>
<option>2001</option>
<option>2002</option>
<option>2003</option>
<option>2004</option>
<option>2005</option>
<option>2006</option>
</select></td>
</tr>
<tr>
<td>Description de photo:</td>
<td><input name="description" type="text" id="description"></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td>Photo upload</td>
<td><input name="picture" type="file" id="picture">
</tr>
<tr>
<td> </td>
<td><input name="uploaden" type="submit" id="uploaden" value="Submit"></td>
</tr>
</table>
</form>
<?php
}
if (true) {
if(trim($_POST['name']) <> "" && trim($_POST['adres']) <> "" && trim($_POST['zipcode']) <> "" && trim($_POST['city']) <> "" && trim($_POST['baby']) <> "" && trim($_POST['day']) <> "" && trim($_POST['month']) <> "" && trim($_POST['year']) <> "" && trim($_POST['description']) <> "" && trim($_POST['email']) <> "" ) {
$name = $_POST['name'];
$adres = $_POST['adres'];
$zipcode = $_POST['zipcode'];
$city = $_POST['city'];
$baby = $_POST['baby'];
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$description = $_POST['description'];
$email = $_POST['email'];
$picture = $_POST['picture'];
mysql_query
("INSERT INTO personal
(name,
adres,
zipcode,
city,
baby,
day,
month,
year,
description,
email,
picture)
VALUES
('".$name."',
'".$adres."',
'".$zipcode."',
'".$city."',
'".$baby."',
'".$day."',
'".$month."',
'".$year."',
'".$description."',
'".$email."',
'".$picture."')") or die(mysql_error());
mysql_close();
}
}
?>
Dit is mijn upload class
<?php
class upload {
var $tmp;
var $path;
var $name;
var $error="";
var $mode;
var $max_size=1024;
var $ext="jpg jpeg gif";
var $file;
var $file_ext;
function upload ($name="",$name_tmp="",$path="") {
if (empty($path))
$this->error .= "<li>The script can't work with an empty path.</li>\n";
if (empty($name) || empty($name_tmp))
$this->error .= "<li>Please select a file to upload</li>\n";
$this->tmp = $name_tmp;
$this->path = $path;
$this->name = $name;
}
function check_extension ($ext="") {
if (!empty($ext))
$this->ext = $ext;
$name = explode(".",$this->name);
$total = count($name)-1; // an array starts with 0 not 1!
$this->file_ext = strtolower($name[$total]);
$this->file = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($this->name)))); // cleanup the file
$this->file = str_replace(".".$this->file_ext,"",$this->file); // get the name without the extension
unset($total);
$ext_perm = explode(" ",$this->ext);
$valid_ext = 0;
$total = count($ext_perm);
for ($i=0; $i<$total; $i++) {
if ($this->file_ext == $ext_perm[$i]) {
$valid_ext = 1;
break;
}
}
if ($valid_ext == 0)
$this->error .= "<li>Only the following extensions will be accepted: ".$this->ext."</li>\n";
}
function check_double($mode="0") {
$this->mode = $mode;
switch ($this->mode) {
case "0": // Stop
if (file_exists($this->path.$this->file.".".$this->file_ext))
$this->error .= "<li>The filename already exists. Please rename your file.</li>\n";
$this->path = $this->path.$this->file.".".$this->file_ext;
break;
case "1": // Rename
$copy = "";
$i = 1;
while (file_exists($this->path.$this->file.$copy.".".$this->file_ext)) {
$copy = "_copy_".$i;
$i++;
}
$this->path = $this->path.$this->file.$copy.".".$this->file_ext;
break;
case "2": // Overwrite
$this->path = $this->path.$this->file.".".$this->file_ext;
break;
default:
$this->error .= "<li>The config of the upload script contains an error. Please contact the webmaster.</li>\n";
break;
}
}
function check_filesize ($file_size,$max_size="") {
if (!empty($max_size))
$this->max_size = $max_size;
$this->max_size = $this->max_size*1024;
if ($file_size >= $this->max_size)
$this->error .= "<li>The filesize (".round($file_size/1024)." kb) of your file is to big. The maximum size is: ".round($this->max_size/1024)." kb.</li>\n";
}
function do_upload () {
if (!empty($this->error)) {
print $this->error;
exit();
}
if (!@move_uploaded_file($this->tmp,$this->path)) {
@unlink($this->tmp);
return false;
}
if ($this->file_ext != "exe")
@chmod ($this->path, 0777);
return true;
}
}
?>
[ Voor 27% gewijzigd door Verwijderd op 13-07-2006 15:45 ]