i am having a heck of a time uploading in php. i found a script on this site but it doesn’t work. here is the code i found here.
<?php
if (eregi("block-Block_Creator.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");
$index = 0;
OpenTable();
if ($step == 'doupload')
{
$internal_error_msg = '';
$upload_dir = '../map/upload/';
$today = date("F j, Y, g:i a");
if ($f_filename_size < 8000000000)
{
#echo "f_filename: $f_filename<BR>
";
#echo "f_filename_name: $f_filename_name<BR>
";
#echo "f_filename_size: $f_filename_size<BR>
";
#echo "f_filename_type: $f_filename_type<BR><BR>
";
if (copy($f_filename, "$upload_dir/$f_filename_name"))
{
echo "$f_filename_name uploaded successfully. ($f_filename_size bytes.)";
$fp = fopen ("$upload_dir/upload.log", "a+");
fwrite($fp, "$today - $f_filename_name uploaded successfully. ($f_filename_size bytes.)
");
fclose($fp);
$emailaddy = 'my_email';
$message = "Hello,
A file has been uploaded:
Filename: $f_filename_name ($f_filename_size bytes)
Download: http://www.domian.com/upload/$f_filename_name
";
mail($emailaddy, "Uploaded file", $message, "From: my_email/
");
}
else
{
# An error occurred during your submission.
$internal_error_msg .= '<DIV class="contentwarning">An error occurred during your upload. Please try
renaming your file and uploading it again.</DIV>';
}
}
else
{
# File too large.
$internal_error_msg .= '<DIV class="contentwarning">The file is too large.</DIV>';
}
unlink($f_filename);
if ($internal_error_msg != "")
{
echo $internal_error_msg;
echo '<BR>';
}
}
closetable();
?>
now i also have an index.php that handles the form that calls the upload.php wich is what i called the file above.
but nothing happens with that script. it just goes to a blank screen and the file doesn’t show in the uplaod folder. so i went looking for another file and found this one.
<?php
if (eregi("block-Block_Creator.php",$PHP_SELF)) {
Header("Location: index.php");
die();
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
include("header.php");
$index = 0;
OpenTable();
$target = "../map/upload/ ";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type ==".php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
CloseTable();
?>
this file works, but when i go to the upload folder and try to move the file to my desktop, it pops up an error message saying an error occured while copying file. so i am not sure the file is all the way there. i have enabled the folder for writing. (777) just learned about this recently. so i am lost as to what i need to do. I am not a programmer and i do not have alot of experience in php. can anyone help.