here are the functions that I use for file uploads
function fileUpload($img,$img_name,$abpath,$debug)
{
//user defined variables
// $abpath is absolute path to where images are uploaded. No trailing slash eg $abpath = "/usr/local/etc/httpd/some/where";
$sizelim = "no"; //yes or no
$size = "60000"; //size limit in bytes
if($debug==1){echo"Path=$abpath<br>URL:$url<p>Image:$img<p>Image_name: $img_name<p>Img_size:$img_size<p>";}
//checks if file was selected to upload
if ($img == 'none') {
echo("No image selected for upload.<br>");
}
else
{
if ($sizelim == "yes") {
if ($img_size > $size) {
die("<b>Error</b> The file you are trying to upload: $img_name must be $size or smaller");
}
}
copy("$img", "$abpath/$img_name") or die("<b>Error:</b> Directory Not Created or chmod correctly");
echo"Image Successfully Uploaded ($img_name)<br>";
}
}
function resize_image($image_name,$new_width,$newname,$debug){
$PicPathIn="/usr/local/etc/httpd/some/where/tempup/";
$PicPathOut="/usr/local/etc/httpd/some/where/";
$PicPathOut2/usr/local/etc/httpd/some/where";
// Picture
$bild="$image_name";
// fileprefix
$tn=$prefix;
$neueBreite=$new_width; //New width
$size=getimagesize("$PicPathIn"."$bild");
$breite=$size[0];
$hoehe=$size[1];
$neueHoehe=intval($hoehe*$neueBreite/$breite);
if($size[2]==2) {
// JPG
$altesBild=ImageCreateFromJPEG("$PicPathIn"."$bild");
$neuesBild=ImageCreate($neueBreite,$neueHoehe);
ImageCopyResized($neuesBild,$altesBild,0,0,0,0,$neueBreite,
$neueHoehe,$breite,$hoehe);
$bild2 = $newname;
ImageJPEG($neuesBild,"$PicPathOut$bild2",85);
}
// close function resize_image
echo"Image $bild2 created and resized to width $neueBreite<br>";
}
//***************************************************************************
function delete_image($img_name,$abpath,$debug){
if(file_exists("$abpath/$img_name"))
{
unlink("$abpath/$img_name");
echo"File $img_name deleted<br><br>";
}else{echo"File $img_name doesn't exists, cannot delete<br><br>";}
}
?>
it was modified from some code a german guy sent me, hence the weird variable names. Make sure all directories are chmodded correctly and you should be fine.
Usage
call the file upload field $file (remember that $file_name exists as the file's name when submitted in a form that is multipart data set in the <form> tag)
fileupload($file,$file_name,$abpath,$debug);
if you want to resize it, upload it to a temp directory, resize it (which copies it to a new size and new filename) and delete the old one using the absolute path.
good luke