$errors = array(1 => 'php.ini max file size exceeded',
2 => 'html form max file size exceeded',
3 => 'file upload was only partial',
4 => 'no file was attached');
count($active_keys)
or error('No files were uploaded', $uploadform);
foreach($active_keys as $key)
{
($_FILES[$fieldname]['error'][$key] == 0)
or error($_FILES[$fieldname]['tmp_name'][$key].': '.$errors[$_FILES[$fieldname]['error'][$key]], $uploadForm);
}
foreach($active_keys as $key)
{
@is_uploaded_file($_FILES[$fieldname]['tmp_name'][$key])
or error($_FILES[$fieldname]['tmp_name'][$key].' not an HTTP upload', $uploadForm);
}
foreach($active_keys as $key)
{
@getimagesize($_FILES[$fieldname]['tmp_name'][$key])
or error($_FILES[$fieldname]['tmp_name'][$key].' not an image', $uploadForm);
}
else {
unlink($uploaddir.$time.'-'.$_FILES[$fieldname]['name'][$key]);
error('You have chosen an image file format that is not supported', $uploadform); }
and finally this part creates the articles to be added to the scroll bar
PHP Code:
function error($error, $location, $seconds = 5)
{
header("Refresh: $seconds; URL=\"$location\"");
echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n".
'"http://www.w3.org/TR/html4/strict.dtd">'."\n\n".
'<html lang="en">'."\n".
' <head>'."\n".
' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
' <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n".
' <title>Upload error</title>'."\n\n".
' </head>'."\n\n".
' <body>'."\n\n".
' <div id="Upload">'."\n\n".
' <h1>Upload failure</h1>'."\n\n".
' <p>An error has occured: '."\n\n".
' <span class="red">' . $error . '...</span>'."\n\n".
' The upload form is reloading</p>'."\n\n".
' </div>'."\n\n".
' <body>'.
'</html>';
exit;
}
$sql="select articleID, title, snippet from article where scrollbar='Yes' AND now() > publishingdate ORDER BY articleID DESC LIMIT 0,5";
$result=mysql_query($sql) or die ("Error!! BAD SELECT SEARCH STATEMENT!!");
$nrows = mysql_num_rows($result);
for($k=0;$k<$arts;$k++) {
$sql2="SELECT Min(imgID) as minimage, imgLoc from articleimages WHERE article='$articleIDs[$k]' group by article";
$result2=mysql_query($sql2) or die ("Error!! BAD SELECT SEARCH STATEMENT!!");
for ($i=0;$i<$arts;$i++) {
if ($i==$arts2) {
$string .= "id$t=$articleIDs[$i]";
}
else {
$string .= "id$t=$articleIDs[$i]&";
}
$t++;
}
$txtfile="../flashnews.txt";
$file = fopen($txtfile, 'w') or die("can't open file");
fwrite($file, $string);
fclose($file);
header("Location: ../success.php");
exit;
}
?>
By the fact that Ive just had to submit my code to 3 different posts sorts of answers my question here but would you recommend me to split this code into three different parts similar to the way I have just done it here? Also the upload images script where it resizes this is rather huge is there a way of compressing this?
to be honest scrap that last thought because I have a simple images upload without an article and once I try and upload that first picture i.e. the 4842px * 2102px I am getting the same error message. I have removed the maxium filesize from the original form if that helps.
I am trying to have an uploading page on my website. When members submit the entry, the entry goes to either the photo page (so .gif, .jpg, .png, etc.) and documents go to the documents page. When they go to the pages, the images would actually put themselves onto the page (so when visitors go to the page they can see the picture, not link to the picture). When they go to the documents page they are given links. Is there a way to do this.
Also, i was wondering if there was any administrator tools that would allow me to accept them to be put up, or delete the ones that are not acceptable?
Thanks Bokeh!! This coding worked perfect and has been a huge help since I have limited php experience. Does anyone know an add on script that i can put in so that after a file is uploaded an email is sent to notify the business that a file has been uploaded?
I am using the main script with success. I am using bokeh's script because of its usability. I did develop a thumbnail script from various sorces but cannot get it working with bokehs cript i think because of the now() timestamp that is used. Is there any way around this?
// make a note of the current working directory, relative to root. $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
// make a note of the directory that will recieve the uploaded file $uploadsDirectory = 'uploaded_files/';
// make a note of the location of the upload form in case we need it $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';
// make a note of the location of the success page $uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';
// fieldname used within the file <input> of the HTML form $fieldname = 'file';
// Now let's deal with the upload
// possible PHP upload errors $errors = array(1 => 'php.ini max file size exceeded', 2 => 'html form max file size exceeded', 3 => 'file upload was only partial', 4 => 'no file was attached');
// check the upload form was actually submitted else print the form isset($_POST['submit']) or error('the upload form is neaded', $uploadForm);
// check for PHP's built-in uploading errors ($_FILES[$fieldname]['error'] == 0) or error($errors[$_FILES[$fieldname]['error']], $uploadForm);
// check that the file we are working on really was the subject of an HTTP upload @is_uploaded_file($_FILES[$fieldname]['tmp_name']) or error('not an HTTP upload', $uploadForm);
include("db.info.php"); mysql_connect($host,$username,$password); mysql_select_db($database) or die( "Unable to select database");;
//add info to database to link to uploaded files $upload = $now.'-'.$_FILES[$fieldname]['name']; $query = "UPDATE my_table SET file = '$upload' WHERE id = '$id'"; $file = mysql_real_escape_string($_POST['file']); $result = mysql_query($query) or die ("Could not run query.");
// If you got this far, everything has worked and the file has been successfully saved. // We are now going to redirect the client to a success page. header('Location: ' . $uploadSuccess);
// The following function is an error handler which is used // to output an HTML error page if the file upload fails function error($error, $location, $seconds = 2) { header("Refresh: $seconds; URL=\"$location\""); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."\n". '"http://www.w3.org/TR/html4/strict.dtd">'."\n\n". '<html lang="en">'."\n". ' <head>'."\n". ' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n". ' <link rel="stylesheet" type="text/css" href="stylesheet.css">'."\n\n". ' <title>Upload error</title>'."\n\n". ' </head>'."\n\n". ' <body>'."\n\n". ' <div id="Upload">'."\n\n". ' <h1>Upload failure</h1>'."\n\n". ' <p>An error has occured: '."\n\n". ' <span class="red">' . $error . '...</span>'."\n\n". ' The upload form is reloading</p>'."\n\n". ' </div>'."\n\n". '</html>'; exit; } // end error handler ?>
any ideas/thoughts greatly appreciated, pullin my hair out!!!!!
include("dbconn.inc.php"); mysql_connect($host,$username,$password); mysql_select_db($database) or die( "Unable to select database");
$uploadname = $now.'-'.$_FILES[$fieldname]['name']; $query = "UPDATE my_table SET file = '$uploadname' WHERE id = '$id'"; mysql_real_escape_string($uploadname); $result = mysql_query($query) or die ("Could not run query.");
// If you got this far, everything has worked and the file has been successfully saved. // We are now going to redirect the client to a success page. header('Location: ' . $uploadSuccess);
Ok, here is what I am seeing. I am hosted on ulmb.com and they do not give you access to file permissions though they say it is automatic. They say I need to change the code to make it not check for permissions. Please tell me how I can do that. Also, I am wanting the uploads to be in Zip format only. Is there a way to make that happen instead of checking for images?
Wow, thanks a lot. I assume I can just plug this code into what already exists in upload.processor.php. Question though ... I received the email letting me know that an image had been uploaded, but the body of the email just said "message content." I understand that the value assigned to $form_data is 'message content' so that's where it came from. But I need it to actually write the content of the form in there.
Do I have to define a variable for every field like:
Ok, the files upload beautifully, and the email actually emails to me, but, I'm having the same problem as CTWorion had, the information within the email just says "name". I've been trying to figure this out for days, obviously I'm a newbie, I don't know what I'm missing and I don't know how to make this work. Here's what I have done:
I hope that someone can help me. If I can just figure out how to get one of the fields to work, I should be able to apply that fix to other field areas, including the files area... I hope.
Ok, the files upload beautifully, and the email actually emails to me, but, I'm having the same problem as CTWorion had, the information within the email just says "name". ...
On my order.form.php:
Slowly getting somewhere, I hope... I changed the code in the upload.processor.php a little bit and now I can at least get the text input for the field 'name' by having changed the code like this:
Used Bokeh's terrific upload script. Genius! But, I'm still working on trying to get it to email the information that was input from my website. Here's where I'm at now, the files upload successfully, the form emails to me successfully, figured out how to have the contact information print in the email but now I'm having trouble figuring out how to have it also give me the names of the files uploaded with the form.
Here's the code from my upload.form.php:
Code:
<?php
// filename: upload.form.php
// first let's set some variables
// make a note of the current working directory relative to root.
$directory_self = str_replace(basename($_SERVER['/home/mysite/public_html/']), '', $_SERVER['/home/mysite/public_html/']);
// make a note of the location of the upload handler
$uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . '/upload.processor.php';
// set a max file size for the html upload form
$max_file_size = 500000; // size in bytes
// now echo the html page
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title>Upload form</title>
</head>
<body>
<form action="<?php echo $uploadHandler ?>" method="post" enctype="multipart/form-data" name="Upload" id="Upload">
<h1>
Inquiry / Order Upload Form</h1>
<div id="order-form">
<form enctype="multipart/form-data" action="upload.processor.php" method="post">
<fieldset id="contact">
<legend><strong>Contact Information:</strong></legend>
<table width="45%" border="0">
<tr>
<td><label for="name">Name:</label>
<input type="text" name="name" id="name" /></td>
<td><label for="address">Address:</label>
<input type="text" name="address" id="address" />
<label for="label"></label></td>
</tr>
<tr>
<td><label for="email">Email:</label>
<input type="text" name="email" id="email" /></td>
<td><label for="phone">Phone :</label>
<input type="text" name="phone" id="phone" /></td>
</tr>
<tr>
<td colspan="2"><strong>Select Service Type:</strong>
<select name="select">
<option value="Select Here" selected>Select Here</option>
<option value="First">First</option>
<option value="Second">Second</option>
<option value="Third">Third</option>
<option value="Fourth">Fourth</option>
</select> </td>
</tr>
<tr>
<td colspan="2"><p> </p>
</td>
</tr>
</table>
<label for="name"></label>
<br>
<label for="address"></label>
</fieldset>
<p>
<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
</p>
<p>
<label for="file1">Photo#1:</label>
<input id="file1" type="file" name="file[]">
</p>
<p>
<label for="file2">Photo#2:</label>
<input id="file2" type="file" name="file[]">
</p>
<p>
<label for="file3">Photo#3:</label>
<input id="file3" type="file" name="file[]">
</p>
<p>Describe service/s requested for each photo separately: </p>
<p>Service Description Photo#1
<textarea name="textfield5" cols="75"></textarea>
</p>
<p>Service Description Photo#2
<textarea name="textfield6" cols="75"></textarea>
</p>
<p>
Service Description Photo#3
<textarea name="textfield7" cols="75"></textarea>
</p>
<p> </p>
<p> </p>
<p>
<label for="submit">Press to...</label>
<input id="submit" type="submit" name="submit" value="Upload">
</p>
<p> </p>
</form>
</body>
</html>
Bookmarks