One small detail, you have to include this php file in another file or you have to add the <html>, <body, etc ... tags.
I've once written a more complicated uploadscript that would create and chmod the directories if needed (sorry for the dutch comments and variables)
CODE
<?php
require_once('session_check.php');
$titel = 'Upload een afbeelding';
$stylesheet = '"../style.css"';
include_once('../html_head.inc');
require_once('resize_image_function.php');
require('SQL_connect.php');
require('SQL_read.php');
$album_folder = read_SQL(album_folder, album);
$folder = $_POST['folder'];
$thumbnail_maximum_heigth = read_SQL(thumbnail_maximum_heigth, thumbnails); //nieuwe maximale hoogte
$thumbnail_maximum_width = read_SQL(thumbnail_maximum_width, thumbnails); //nieuwe maximale breedte
$thumbnail_herschaal = read_SQL(thumbnail_herschaal, thumbnails); //herschaalmodus
$thumbnail_jpeg_kwaliteit = read_SQL(thumbnail_jpeg_kwaliteit, thumbnails); //JPEG kwaliteit van thumbnail
$upload_max_size = read_SQL(upload_max_size, upload);
$upload_maximum_heigth = read_SQL(upload_max_height, upload); //nieuwe maximale hoogte
$upload_maximum_width = read_SQL(upload_max_width, upload); //nieuwe maximale breedte
$upload_jpeg_kwaliteit = read_SQL(upload_jpeg_kwaliteit, upload); //JPEG kwaliteit van upload
$uploadmap = '/home/wutske/public_html/PHP/' . $album_folder . '/' . $folder;
$tijdelijk_bestand = $_FILES['afbeelding1']['tmp_name'];
$bestandsnaam = $_FILES['afbeelding1']['name'];
if (isset($_POST['afbeelding_submit']))
{
if (!file_exists($uploadmap))
{
if (is_writable('/home/wutske/public_html/PHP/' . $album_folder))
{
if (mkdir($uploadmap))
{
echo $uploadmap . ' aangemaakt <br />';
if (chmod($uploadmap, 0777));
echo 'Rechten gewijzigd naar 0777<br />';
}
else
{
die('Aanmaken uploadmap gefaald !');
}
}
else
die('De hoofd-albummap is niet beschrijfbaar, gelieve deze te chmodden');
}
if (is_writable($uploadmap))
{
//controleert bestandsgrootte
if ($_FILES['afbeelding1']['size'] > $upload_max_size)
{
//verwijderen tijdelijk bestand indien te groot
if (unlink($_FILES['afbeelding1']['tmp_name']))
echo '<div class="warning">Tijdelijk bestand verwijderd, reden: ';
//echo indien tijdelijk bestand verwijderd. Altijd die indien te groot bestand.
die('Bestand is te groot, de maximale grootte is ' . $upload_max_size . '. Bestandgroote = ' . $_FILES['afbeelding1']['size'] . '</div>');
}
else
{
//aanmaken thumbnail:
if ( !file_exists($uploadmap . '/thumbnails'))
{
echo '<div class="info">De thumbnail folder bestaat nog niet, deze wordt aagemaakt</div>';
if (!is_writable($uploadmap))
{
echo '<div class="info">De album folder is niet beschrijfbaar, er wordt geprobeert deze beschrijfbaar te maken: </div>';
/*if (chmod($set_map, 0777))
echo '<div class="info">De thumbnail folder is nu beschrijfbaar</div>';
else
echo '<div class="error">Kon de thumbnail folder niet beschrijfbaar maken ... u krijg waarschijnlijk een hele resem errors ...<br />
Gelieve de folder schrijfbaar te maken via bv. FTP</div>';
*/
}
else
{
mkdir($uploadmap . '/thumbnails', 0777);
chmod($uploadmap . '/thumbnails', 0777);
}
}
else
{
if (!is_writable($uploadmap . '/thumbnails'))
{
echo '<div class="info">De thumbnail folder is niet beschrijfbaar, er wordt geprobeert deze beschrijfbaar te maken: </div>';
if (chmod($thumbnail_folder, 0777))
{
echo '<div class="info">De thumbnail folder is nu beschrijfbaar</div>';
}
else
{
echo '<div class="error">Kon de thumbnail folder niet beschrijfbaar maken ... u krijg waarschijnlijk een hele resem errors ...<br />
Gelieve de folder schrijfbaar te maken via bv. FTP</div>';
}
//chown($thumbnail_folder, 32106);
}
}
resize_image('', $tijdelijk_bestand, 'tn_', $_FILES['afbeelding1']['name'], $uploadmap, '/thumbnails', $thumbnail_maximum_width, $thumbnail_maximum_heigth, $thumbnail_herschaal, $thumbnail_jpeg_kwaliteit);
if ($_POST['resize'] !== 'y')
{
//indien er een fout is opgetreden bij het verplaatsten van het tijdelijk bestand
if (!(move_uploaded_file($_FILES['afbeelding1']['tmp_name'], $uploadmap . '/' . $bestandsnaam)))
{
//Bij fout, tijdelijk bestand verwijderen, indien verwijderd, eerste die, indien niet, die fatal error).
if (unlink($_FILES['afbeelding1']['tmp_name']))
die('<div class="warning">Er is een fout opgetreden ... het tijdelijk bestand is verwijderd.</div>');
else
die('<div class="warning">Fatal error: Upload niet succesvol en tijdelijk bestand niet verwijderd</div>');
}
else
{
echo 'Bestand succesvol geuploaded naar: ' . $uploadmap . '/' . $bestandsnaam;
}
}
else
{
//Herschalen van het geuploaded bestand
resize_image('', $tijdelijk_bestand, '', $_FILES['afbeelding1']['name'], $uploadmap, '', $upload_maximum_width, $upload_maximum_heigth, 2, $upload_jpeg_kwaliteit);
}
}
}
else
die('<div class="warning">Kan niet schrijven in de map ' . $uploadmap . '</div>');
}
else
{
echo 'Uploaden naar: ' . $uploadmap;
echo '<br />De Maximale grootte is ' . ( $upload_max_size / 1024 ) . ' KB';
?>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="
<?php
echo upload_max_size
?>
" />
<!-- Name of input element determines name in $_FILES array -->
<table>
<tr>
<td width ="100px">
Bestand 1:
</td>
<td>
<input name="afbeelding1" type="file" size="100" /><br />
</td>
</tr>
<tr>
<td width="100px">
Map
</td>
<td>
<input type="textbox" name="folder" />
</td>
</tr>
<tr>
<td width="100px">
Herschaal ?
</td>
<td>
<input type="checkbox" name="resize" value="y" checked="cheched"/>
</td>
</tr>
</table>
<input type="submit" name="afbeelding_submit" value="Send File" />
</form>
<?php
}
?>
Comment/Reply (w/o sign-up)