File Uploading using $_File[""]
Posted: Mon Sep 22, 2008 4:08 am
Hi,
This is the first time Im uploading a file. My form and action are in two different pages, And the file dosen't get uploaded or the file name is also not stored in the database.
This is the below code:
Form page:
Action page:
I'm unable to get the "filename" value in the action page. The database does not have store the file name as well..
More Info:
Im using Joomla system.
There is already upload file module in one another system working.
Any suggestions folks??
Thanks
This is the first time Im uploading a file. My form and action are in two different pages, And the file dosen't get uploaded or the file name is also not stored in the database.
This is the below code:
Form page:
Code: Select all
<body>
<span class="tblTD tblBT tblBR tblBB">
<form name="Confirm" method="post" action="<?=$mosConfig_live_site?>index.php?option=com_content&task=view&id=479&Itemid=395" enctype="multipart/form-data">
<label>
<input type="file" name="projPic" value="" />
</label>
<br />
Files can be only GIF, JPG or PNG formats <br />
and max of image size is 300px wide, 200px high<br />
<br />
<input type="image" src='<?=$mosConfig_live_site?>/images/proj_Add.gif' alt='Add New Project' border='0' />
</form>
</body>
Code: Select all
$uploadpath = $mosConfig_absolute_path.'/images/profile-images/WC/';
$imageLocation = $mosConfig_live_site.'/images/profile-images/WC/';
echo "Return Code : " . $_FILES["projPic"]["error"] ."<br>";
echo "Uploading projPic: " . $_FILES["projPic"]["name"]."<br>";
if ($_FILES["projPic"]["name"]) { //$_FILES['projPic']['size'] > 0
if ((($_FILES["projPic"]["type"] == "image/gif") ||
($_FILES["projPic"]["type"] == "image/jpeg") ||
($_FILES["projPic"]["type"] == "image/pjpeg")||
($_FILES["projPic"]["type"] == "image/png")) &&
($_FILES["projPic"]["size"] < 40960)) { //40960 bits => 40 kilobits => 5 KB
//|| ($_FILES["file"]["type"] == “application/vnd.ms-excel”)|| ($_FILES["file"]["type"] == “application/msword”)
$filename=$joomlaid.'-'.substr(substr($_FILES["projPic"]["name"],0,strlen($_FILES["projPic"]["name"])-4), 0, 14).'-projPic'.substr($_FILES["projPic"]["name"],strlen($_FILES["projPic"]["name"])-4,4).'-'.$projID;
$destination=$uploadpath.$filename;
if (is_file($destination)) unlink($destination);
if (!move_uploaded_file($_FILES["projPic"]["tmp_name"], $destination)) {
$errors.="Upload file failed";
}
list($width,$height)=getimagesize($destination);
if ($width>300 || $height>200) {
unlink($destination);
$errors.="Error: the width or height of ".$_FILES["projPic"]["name"]." is too large";
}
else $projPicx=$filename;
}
else {
$errors.="Error: " . $_FILES["projPic"]["name"] . " wrong file type or file size too big, Max 40 bites <br />";
}
}
echo "filename: ".$filename."<br>";
$fullImage = $imageLocation.$filename;
$queryUpdate = mysql_query("UPDATE tbl_pros SET ProjectPicURL='$fullImage' WHERE ProjectOrgJosUserID='$joomlaid' AND ProjectID='$projID' ");
More Info:
Im using Joomla system.
There is already upload file module in one another system working.
Any suggestions folks??
Thanks