JavaScript is not enabled on your browser and in order to properly use Coder Profile JavaScript is required.
To view instructions on how to enable JavaScript on your browser click here .
I have this code for my topic image upload:
CODE:
Copy / Restore :: Remove Scroll Bars
<form method="post" enctype="multipart/form-data">
<table align="center">
<tr>
<td>Title:</td>
<td><input type="text" name="title" style="width:
500px;" maxlength="40" /></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name="body" style="width: 500px; height: 250px;"
maxlength="5000" /></textarea></td>
</tr>
<tr>
<td>Include Image?:
<td><input type="file" name="data" id="file"
/></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Post it!"
/></td>
</tr>
</table>
</form>
Select what you want to copy and in doing so you will keep the formatting when pasting it.
CODE:
Copy / Restore :: Remove Scroll Bars
if(isset($_POST['data'])){
$max_filesize = 999999;
$filetypes =
array('image/jpg','image/jpeg','image/JPG','image/JPEG',
9;image/gif','image/GIF','image/png','image/PNG','image/tiff
','image/TIFF','image/bmp','image/BMP');
$upload_path = '/uploads/';
# Check to see if the filesize is too large
if ($_FILES['data']['size'] > $max_filesize) {
die('Your filesize is too large. Please make your filesize smaller than ' .
$max_filesize . ' bytes. ( 10mb )');
}
// End if filesize is too large
list($height, $width) = getimagesize($FILES['data']['name']);
# Check to see if the filetype is correct
if (!in_array($_FILES['data']['type'], $filetypes)) {
die('Sorry, your file was not a jpg, jpeg, gif, png, tiff, or a bmp. (Yours was ' .
$_FILES['data']['type'] . ')');
}
// End filetype check
# If file has gotten this far, it is successful
$where = $_SERVER['DOCUMENT_ROOT'] . $upload_path .
$_FILES['data']['name'];
$file = 'http://www.blindtosound.com' . $upload_path .
$_FILES['data']['name'];
# Upload the file
$upload = move_uploaded_file($_FILES['data']['tmp_name'], $where);
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
}
Select what you want to copy and in doing so you will keep the formatting when pasting it.
I'm having 2 problems with this.
1. It's not uploading the file
2. It's not inserting the image path into the database (That part comes later in the code..)
It's not returning any errors, either.
Hi ya,
It returned loads of errors. I just followed the errors and fixed them line by line.
CODE:
Copy / Restore :: Remove Scroll Bars
<?php
if(isset($_FILES['data'])){
$max_filesize = 999999;
$filetypes =
array('image/jpg','image/jpeg','image/JPG','image/JPEG',
9;image/gif','image/GIF','image/png','image/PNG','image/tiff
','image/TIFF','image/bmp','image/BMP');
$upload_path = '/uploads/';
# Check to see if the filesize is too large
if ($_FILES['data']['size'] > $max_filesize) {
die('Your filesize is too large. Please make your filesize smaller than ' .
$max_filesize . ' bytes. ( 10mb )');
}
// End if filesize is too large
list($height, $width) = getimagesize($_FILES['data']['tmp_name']);
# Check to see if the filetype is correct
if (!in_array($_FILES['data']['type'], $filetypes)) {
die('Sorry, your file was not a jpg, jpeg, gif, png, tiff, or a bmp. (Yours was ' .
$_FILES['data']['type'] . ')');
}
# Upload the file
$filename = mt_rand(); //preappend file with a random number to reduce chance of another file
being uploaded with the same name.
$upload = move_uploaded_file($_FILES['data']['tmp_name'], 'uploads/'
. $filename . '_' . $_FILES['data']['name']);
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
}
?>
<form method="post" enctype="multipart/form-data">
<table align="center">
<tr>
<td>Title:</td>
<td><input type="text" name="title" style="width:
500px;" maxlength="40" /></td>
</tr>
<tr>
<td>Message:</td>
<td><textarea name="body" style="width: 500px; height: 250px;"
maxlength="5000" /></textarea></td>
</tr>
<tr>
<td>Include Image?:
<td><input type="file" name="data" id="file"
/></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Post it!"
/></td>
</tr>
</table>
</form>
Select what you want to copy and in doing so you will keep the formatting when pasting it.
Since you said there were no errors showing, make sure you have not turned off the display of errors in your php.ini file.
Kind regards,
Scott
Ahhh, thanks so much, Scott.
As for my php.ini file, I haven't touched it at all since I got my hosting..So it's still the default, I guess
CODE:
Copy / Restore :: Remove Scroll Bars
register_globals = Off
zend_extension="/usr/local/IonCube/ioncube_loader_lin_4.4.so"
zend_extension_ts="/usr/local/IonCube/ioncube_loader_lin_4.4_ts.so"
[Zend]
zend_optimizer.optimization_level=15
zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3
zend_optimizer.version=3.3.3
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so
Select what you want to copy and in doing so you will keep the formatting when pasting it.
Well, Scott. That doesn't exactly work the way I had wanted it to. It allows the image to be posted IF there's an image in the field. If there's not an image in the field to be uploaded, it returns errors. I only want the image upload code to run if there's something in the field to be uploaded. =/
CODE:
Copy / Restore :: Remove Scroll Bars
if(isset($_FILES['data'])){
$max_filesize = 999999;
$filetypes =
array('image/jpg','image/jpeg','image/JPG','image/JPEG',
9;image/gif','image/GIF','image/png','image/PNG','image/tiff
','image/TIFF','image/bmp','image/BMP');
$upload_path = '/uploads/';
# Check to see if the filesize is too large
if ($_FILES['data']['size'] > $max_filesize) {
die('Your filesize is too large. Please make your filesize smaller than ' .
$max_filesize . ' bytes. ( 10mb )');
}
// End if filesize is too large
list($height, $width) = getimagesize($_FILES['data']['tmp_name']);
# Check to see if the filetype is correct
if (!in_array($_FILES['data']['type'], $filetypes)) {
die('Sorry, your file was not a jpg, jpeg, gif, png, tiff, or a bmp. (Yours was ' .
$_FILES['data']['type'] . ')');
}
# Upload the file
$filename = mt_rand(); //preappend file with a random number to reduce chance of another file
being uploaded with the same name.
$upload = move_uploaded_file($_FILES['data']['tmp_name'], 'uploads/'
. $filename . '_' . $_FILES['data']['name']);
$file = "http://www.blindtosound.com/uploads/". $filename . '_' .
$_FILES['data']['name'];
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
}
Select what you want to copy and in doing so you will keep the formatting when pasting it.
It works wonderfully IF there's an image in the field, but when they're not, it returns the errors anyways as if there was.
also check for $_POST['data'] to check that the forms been filled in
I tried both $_POST and $_FILES
Not using isset, use empty
if (empty($_POST['data'])) {....
Still not working. I'll send the whole page, because I'm confused now..
CODE:
Copy / Restore :: Remove Scroll Bars
<?php
include("connect.php");
include("functions.php");
if(!isset($_SESSION['logged'])){
$_SESSION['error'] = "You need to be logged in to post a topic";
header("Location: http://www.blindtosound.com/");
}
if(isset($_POST['submit'])){
if(isset($_SESSION['logged'])){
$username = mysql_real_escape_string($_SESSION['logged']);
$title = htmlentities(mysql_real_escape_string($_POST['title']));
$body = htmlentities(mysql_real_escape_string($_POST['body']));
// ----------------- Errors ----------------
if(empty($title) || empty($body)){
$empty = true;
}
if(preg_match("/[^\sa-zA-Z0-9-?!&'\":,.]/", $title)){
$char = true;
}
if($empty == true){
echo "<div class='error'>" . error("You need to fill in all of the
forms!") . "</div>";
}
if($char == true){
echo "<div class='error'>" . error("The title's characters
need to be a-z, A-Z, 0-9, hyphens, question marks, and spaces!") . "</div>";
}
// --------------- End of Errors -------------
// ----------------- Start of File Upload --------------------
if(!empty($_FILES['data'])){
$max_filesize = 999999;
$filetypes =
array('image/jpg','image/jpeg','image/JPG','image/JPEG',
9;image/gif','image/GIF','image/png','image/PNG','image/tiff
','image/TIFF','image/bmp','image/BMP');
$upload_path = '/uploads/';
# Check to see if the filesize is too large
if ($_FILES['data']['size'] > $max_filesize) {
die('Your filesize is too large. Please make your filesize smaller than ' .
$max_filesize . ' bytes. ( 10mb )');
}
// End if filesize is too large
list($height, $width) = getimagesize($_FILES['data']['tmp_name']);
# Check to see if the filetype is correct
if (!in_array($_FILES['data']['type'], $filetypes)) {
die('Sorry, your file was not a jpg, jpeg, gif, png, tiff, or a bmp. (Yours was ' .
$_FILES['data']['type'] . ')');
}
# Upload the file
$filename = mt_rand(); //preappend file with a random number to reduce chance of another file
being uploaded with the same name.
$upload = move_uploaded_file($_FILES['data']['tmp_name'], 'uploads/'
. $filename . '_' . $_FILES['data']['name']);
$file = "http://www.blindtosound.com/uploads/". $filename . '_' .
$_FILES['data']['name'];
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
}
// ------------------ End of File Upload ---------------------
mysql_query("INSERT INTO `topics` (`title`, `body`, `username`, `topbump`, `lastpost`,
`image`, `imgheight`, `imgwidth`) VALUES ('$title', '$body',
'$username', '$topbump', '$username', '$file',
'$height', '$width')") or die(mysql_error());
mysql_query("UPDATE `users` SET `postcount` = `postcount` + 1 WHERE `username` =
'$username'") or die(mysql_error());
$topbump = mysql_insert_id();
$redir = mysql_fetch_array(mysql_query("SELECT * FROM `topics` ORDER BY `id` DESC LIMIT
1")) or die(mysql_error());
$redir = $redir['id'];
mysql_query("UPDATE `topics` SET `topbump` = '$topbump' WHERE `id` =
'$redir'") or die(mysql_error());
header("Location: http://www.blindtosound.com/topic/$redir");
}
}
mysql_close();
ob_end_flush();
?>
Select what you want to copy and in doing so you will keep the formatting when pasting it.
CODE:
Copy / Restore :: Remove Scroll Bars
if(isset($_FILES['data'])){
$max_filesize = 999999;
$filetypes =
array('image/jpg','image/jpeg','image/JPG','image/JPEG',
9;image/gif','image/GIF','image/png','image/PNG','image/tiff
','image/TIFF','image/bmp','image/BMP');
$upload_path = 'uploads/';
#make sure a file was uploaded
if ($_FILES['data']['error'] != 4) {
# Check to see if the filesize is too large
if ($_FILES['data']['size'] > $max_filesize) {
die('Your filesize is too large. Please make your filesize smaller than ' .
$max_filesize . ' bytes. ( 10mb )');
}
// End if filesize is too large
list($height, $width) = getimagesize($_FILES['data']['tmp_name']);
# Check to see if the filetype is correct
if (!in_array($_FILES['data']['type'], $filetypes)) {
die('Sorry, your file was not a jpg, jpeg, gif, png, tiff, or a bmp. (Yours was ' .
$_FILES['data']['type'] . ')');
}
# Upload the file
$filename = mt_rand(); //preappend file with a random number to reduce chance of another file
being uploaded with the same name.
$upload = move_uploaded_file($_FILES['data']['tmp_name'],
'uploads/' . $filename . '_' . $_FILES['data']['name']);
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
} else {
print 'No file was selected to upload';
}
}
Select what you want to copy and in doing so you will keep the formatting when pasting it.
You do not have permission to post replies to topics in this board. If you want to join in with discussions and create new topics please register. If you want to register your own free account with us, please click here .