Page 1 of 1
Where to start with upload?
Posted: Wed Jun 22, 2005 5:04 am
by ianhull
Hi all,
I would like to be able to upload image files to my server in a directory call uploads
I do not know where to start.
I can create a html form with
Code: Select all
<form name="e;uploaded"e; id="e;uploaded"e; enctype="e;multipart/form-data"e; method="e;post"e; action="e;"e;>
<input type="e;file"e; name="e;file"e; />
</form>
I have set the directory uploads to chmod 777
The image path I would like to be stored in the database in table name
properties row
pic1
Can anyone help me in getting this sort of thing to work?
I have read through the upload threads on this forum but I do not understand them
Thanks
Posted: Wed Jun 22, 2005 5:09 am
by shiznatix
Posted: Wed Jun 22, 2005 6:55 am
by zippee
Here's the code I use in my website
Code: Select all
// make sure something there...
if($_FILES["file"]["size"] > 0) {
// make all lower-case. eg. GIF => gif
$file = strtolower($_FILES["file"]);
echo "File : ";
$fileName = strtolower(basename($file["name"]));
$ext = substr($fileName, -3, 3);
// filetr what you want
$accept = array('jpg','png','gif','jpeg');
// limit the upload size to avoid abuse to system
if ($file["size"] > 500000) {
echo "Filesize over 500 KB limit.<br>\n";
}
elseif(!in_array($ext, $accept)) {
echo "Invalid file format. <br>\n";
}
// no error found... proceed to upload
else {
// set folder path to which image uploaded
$uploaddir = "/uploadfolder/";
//copy the file to some permanent location
if (move_uploaded_file($file["tmp_name"], $uploaddir . $file["name"])) {
echo $file["name"]." uploaded.<br>\n";
} else {
echo "Error found. Please try again. <br>\n";
}
} else {
echo "Empty ...<br>\n";
}
Posted: Wed Jun 22, 2005 6:59 am
by ianhull
Thanks for the help guys,
Much appreciated. Luckily for me I have just been told by another staff member that we have a little dreamweaver extention called pure php upload which seems to do the trick of uploading from form1
One thing with this though is that I do not know how to add the path from form1 into my database.
Any ideas?
Code: Select all
<?php require_once('ScriptLibrary/incPureUpload.php'); ?>
<?php
// Pure PHP Upload 2.1.2
if (isset($HTTP_GET_VARS['GP_upload'])) {
$ppu = new pureFileUpload();
$ppu->path = "web/uploads";
$ppu->extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName = "form1";
$ppu->storeType = "path";
$ppu->sizeLimit = "3000";
$ppu->nameConflict = "uniq";
$ppu->requireUpload = "false";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "blueFlashProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->checkVersion("2.1.2");
$ppu->doUpload();
$uploadGoTo = "123.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$uploadGoTo .= (strpos($uploadGoTo, '?')) ? "&" : "?";
$uploadGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $uploadGoTo));
}
$GP_uploadAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
if (!eregi("GP_upload=true", $HTTP_SERVER_VARS['QUERY_STRING'])) {
$GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING']."&GP_upload=true";
} else {
$GP_uploadAction .= "?".$HTTP_SERVER_VARS['QUERY_STRING'];
}
} else {
$GP_uploadAction .= "?"."GP_upload=true";
}
if (isset($editFormAction)) {
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
if (!eregi("GP_upload=true", $HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "&GP_upload=true";
}
} else {
$editFormAction .= "?GP_upload=true";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language='javascript' src='ScriptLibrary/incPureUpload.js'></script>
</head>
<body>
<form action="<?php echo $GP_uploadAction; ?>" method="post" enctype="multipart/form-data" name="form1" onSubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',false,3000,'','','','','','');showProgressWindow('blueFlashProgress.htm',300,100);return document.MM_returnValue">
<p>
<input name="file" type="file" onChange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',false,3000,'','','','','','')">
</p>
<p><input type="submit" value="submit"></p>
</form>
Posted: Wed Jun 22, 2005 8:06 am
by zippee
Unless you host on your own server. Many hostings do not support dreamweaver extention and may not allow you to upload any module.
Posted: Wed Jun 22, 2005 10:36 am
by ianhull
Sorry a little misunderstanding.
The dreamweaver extention is a plugin and it generates javascript and php code from a form field so no actual extention is being used by the server.
.mxp is the plugin extention
What I am trying to achieve is:
The file that is uploaded from form1 in the code above is somewhere storing a variable but I do not know where.
I would like to retrieve the value from this variable and store it in my db so that I have the path to the image in the db.
Any help or suggestions are much appreciated.
Thanks