stu17
12-19-2004, 11:00 PM
Hello :)
I have this form: http://webstarters.co.nz/stuartw/nz_biz/contact.htm (Iam still working it)
What I what to do is allow people to upload images for example logos etc.... if they want (Where it says “Attach Company logo:” Attach image 1:, Attach image 2:,)
Does any one know of a php script that allows you to do this?
Thanks in advise :)
Sam_GHS
12-20-2004, 04:14 AM
Take a look here:
http://php.resourceindex.com/Functions_and_Classes/File_Management/File_Uploading/
Hope you can find something you want!
Merry Christmas!!
Angelo
12-20-2004, 08:03 AM
The code i use for uploading.
Assumptions - "dosya" is the name of the file variable from the post , "file" is the directory to upload (must be writable)
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$upload_dir = "file/";
$upload_url = $url_dir."/file/";
$message ="";
if (!is_dir("file")) {
die ("upload_files directory doesn't exist - consult your system administrator");
}
if ($_FILES['dosya']) {
$message = do_upload($upload_dir, $upload_url);
}
else {
$message = "Invalid File Specified.";
}
print $message; //comment here to avoid printing the result
function do_upload($upload_dir, $upload_url) {
$temp_name = $_FILES['dosya']['tmp_name'];
$file_name = $_FILES['dosya']['name'];
$login = $HTTP_COOKIE_VARS["viastream"];
$file_type = $_FILES['dosya']['type'];
$file_size = $_FILES['dosya']['size'];
$result = $_FILES['dosya']['error'];
$file_url = $upload_url.$file_name;
$file_path = $upload_dir.$file_name;
if ( $file_name =="") {
$message = "Bad File Name";
return $message;
}
elseif (is_file($file_path)) {
$message = "This file already exists please rename your local file and try again";
return $message;
}
else if ( $file_size > 5000000) {
$message = "Filesize must be lesser than 500 KB - consult your system administrator";
return $message;
}
else if ( $file_type == "text/plain" ) {
$message = "You can not send this type of file - consult your system administrator" ;
return $message;
}
$result = move_uploaded_file($temp_name, $file_path);
$message = ($result)?"You have succesfully uploaded your file - <a href=\"upload.php\">Click here to continue</a>" :
return $message;
}
go with other form processings ...