Upload_File
am 10.02.2010 12:16:43 von Bilal Ahmad
--001485f8612e4db005047f3d2b56
Content-Type: text/plain; charset=ISO-8859-1
Hi I am trying to make a form to provide option to user to upload a file on
a server.Here is the code for my upload.php. It checks all the conditions
etc.. . This code works fine on localhost , and file is uploaded
successfully. But when I use this script online on my server, it gives me
error. couldn't figure out what is error.
What I think is error in move_upload_file, but it isn't returning any error.
File permissions on upload folder are 755.
if((!empty($_FILES['uploaded_file'])) && ($_FILES['uploaded_file']['error']
== 0)){
$ok = 0;
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg" || "gif" || "png") && ($_FILES["uploaded_file"]["type"]
== "image/jpeg" || "image/gif" || "image/png") &&
($_FILES["uploaded_file"]["size"] < 2097152) ){
$newname = 'upload/'.$filename;
if (!file_exists($newname)) {
if
((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$n ewname))) {
$ok = "1";
echo "It's done! The file has been saved as: ".$newname;
} else {
echo "Error: A problem occurred during file upload!"; //This one
executes when ever i try to upload file on server.
}
} else {
echo "Error: File ".$_FILES["uploaded_file"]["name"]." already
exists";
}
} else {
echo "Error: Only .jpg images under 2MB are accepted for upload";
}
} else {
echo "Error: No file uploaded";
}
Thanks
Bilal Farooq Ahmad
--001485f8612e4db005047f3d2b56--
Re: Upload_File
am 10.02.2010 12:35:11 von bedul
--00504502ae635e3f73047f3d6d46
Content-Type: text/plain; charset=ISO-8859-1
u should type the error here
and attach the file not type in msgbox below
what permision for upload folder?
On Wed, Feb 10, 2010 at 6:16 PM, Bilal Ahmad
> wrote:
> Hi I am trying to make a form to provide option to user to upload a file on
> a server.Here is the code for my upload.php. It checks all the conditions
> etc.. . This code works fine on localhost , and file is uploaded
> successfully. But when I use this script online on my server, it gives me
> error. couldn't figure out what is error.
> What I think is error in move_upload_file, but it isn't returning any
> error.
> File permissions on upload folder are 755.
>
>
>
> if((!empty($_FILES['uploaded_file'])) && ($_FILES['uploaded_file']['error']
> == 0)){
>
> $ok = 0;
> $filename = basename($_FILES['uploaded_file']['name']);
>
> $ext = substr($filename, strrpos($filename, '.') + 1);
>
> if (($ext == "jpg" || "gif" || "png") && ($_FILES["uploaded_file"]["type"]
> == "image/jpeg" || "image/gif" || "image/png") &&
> ($_FILES["uploaded_file"]["size"] < 2097152) ){
>
> $newname = 'upload/'.$filename;
>
> if (!file_exists($newname)) {
>
> if
> ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$n ewname))) {
> $ok = "1";
> echo "It's done! The file has been saved as: ".$newname;
> } else {
> echo "Error: A problem occurred during file upload!"; //This one
> executes when ever i try to upload file on server.
> }
> } else {
> echo "Error: File ".$_FILES["uploaded_file"]["name"]." already
> exists";
> }
> } else {
> echo "Error: Only .jpg images under 2MB are accepted for upload";
> }
> } else {
> echo "Error: No file uploaded";
> }
>
> Thanks
> Bilal Farooq Ahmad
>
--
akan ada dimana mulut terkunci dan suara tak ada lagi..
saat itu gunakanlah HP untuk melakukan SMS!!
-> ini aliran bedul.. bukan aliran aneh.
tertawa sebelum tertawa didepan RSJ..
--00504502ae635e3f73047f3d6d46--
Re: Upload_File
am 10.02.2010 12:54:41 von Eric Lee
--0016361e874e15cf94047f3db3cc
Content-Type: text/plain; charset=UTF-8
On Wed, Feb 10, 2010 at 7:35 PM, Gunawan Wibisono wrote:
> u should type the error here
> and attach the file not type in msgbox below
>
> what permision for upload folder?
>
> On Wed, Feb 10, 2010 at 6:16 PM, Bilal Ahmad <
> engg.bilalmalik@googlemail.com
> > wrote:
>
> > Hi I am trying to make a form to provide option to user to upload a file
> on
> > a server.Here is the code for my upload.php. It checks all the conditions
> > etc.. . This code works fine on localhost , and file is uploaded
> > successfully. But when I use this script online on my server, it gives me
> > error. couldn't figure out what is error.
> > What I think is error in move_upload_file, but it isn't returning any
> > error.
> > File permissions on upload folder are 755.
> >
> >
> >
> > if((!empty($_FILES['uploaded_file'])) &&
> ($_FILES['uploaded_file']['error']
> > == 0)){
> >
> > $ok = 0;
> > $filename = basename($_FILES['uploaded_file']['name']);
> >
> > $ext = substr($filename, strrpos($filename, '.') + 1);
> >
> > if (($ext == "jpg" || "gif" || "png") &&
> ($_FILES["uploaded_file"]["type"]
> > == "image/jpeg" || "image/gif" || "image/png") &&
> > ($_FILES["uploaded_file"]["size"] < 2097152) ){
> >
> > $newname = 'upload/'.$filename;
> >
> > if (!file_exists($newname)) {
> >
> > if
> > ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$n ewname))) {
> > $ok = "1";
> > echo "It's done! The file has been saved as: ".$newname;
> > } else {
> > echo "Error: A problem occurred during file upload!"; //This
> one
> > executes when ever i try to upload file on server.
> > }
> > } else {
> > echo "Error: File ".$_FILES["uploaded_file"]["name"]." already
> > exists";
> > }
> > } else {
> > echo "Error: Only .jpg images under 2MB are accepted for upload";
> > }
> > } else {
> > echo "Error: No file uploaded";
> > }
> >
>
Bilal
hmmm .. Some advice
is the $_FILES filled correcly
check if the apache server user able access to the upload folder
Check if the tmp is writable by apache user
Regards,
Eric,
> Thanks
> > Bilal Farooq Ahmad
> >
>
>
>
> --
> akan ada dimana mulut terkunci dan suara tak ada lagi..
> saat itu gunakanlah HP untuk melakukan SMS!!
> -> ini aliran bedul.. bukan aliran aneh.
> tertawa sebelum tertawa didepan RSJ..
>
--0016361e874e15cf94047f3db3cc--
Re: Upload_File
am 10.02.2010 13:00:46 von Chaitanya Yanamadala
--0015175884b60d5bae047f3dca86
Content-Type: text/plain; charset=UTF-8
hai farooq
I think the issue is with the max_execution_time in the php.ini of the
server. try modifying this to the maximum level.
also for your code i have modified this a little bit..
*
//Working for uploading the files of a particular type
if(isset($_POST['submit_x']))
{
function file_upload_error_message($error_code)
{
switch ($error_code)
{
case 0:
return 'There is no error, the file uploaded with success...';
case 1:
return 'The uploaded file exceeds the upload_max_filesize
directive in php.ini';
case 2:
return 'The uploaded file exceeds the MAX_FILE_SIZE directive
that was specified in the HTML form';
case 3:
return 'The uploaded file was only partially uploaded';
case 4:
return 'No file was uploaded';
case 6:
return 'Missing a temporary folder';
case 7:
return 'Failed to write file to disk';
case 8:
return 'File upload stopped by extension';
default:
return 'Unknown upload error';
}
}
$host="localhost";
$user="root";
$pass="admin";
$db="develop";
mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$query="select type_name from filetype";
$result=mysql_query($query);
ini_set("display_errors",1);
//error_reporting(E_ALL);
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$uploaded_type=strtolower(substr($_FILES['uploaded']['name'] ,strrpos($_FILES['uploaded']['name'],'.')+1));
print_r($_FILES['uploaded']);
$error_code=$_FILES['uploaded']['error'];
$error_message = file_upload_error_message($error_code);
echo "Name ".$_FILES['uploaded']['name']."
";
echo "Type ".$_FILES['uploaded']['type']."
";
echo "Error ".$error_message."
";
echo "Size ".$_FILES['uploaded']['size']."
";
//echo "
FileX ".$uploaded_type;
while($row = mysql_fetch_array($result))
{
if($uploaded_type==$row['type_name'])
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'],
$target))
{
echo "The file ". basename( $_FILES['uploaded']['name']). "
has been uploaded";
break;
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
}
}
?>*
and this should be the table format
*
DROP TABLE IF EXISTS `filetype`;
CREATE TABLE `filetype` (
`type_name` varchar(10) NOT NULL default '',
PRIMARY KEY (`type_name`)
) TYPE=MyISAM;
/*Data for the table `filetype` */
insert into `filetype`(`type_name`) values
('doc'),('gif'),('jpg'),('pdf'),('png');*
Chaitanya
"A man can get discouraged many times but he is not a failure until he stops
trying..."
On Wed, Feb 10, 2010 at 5:24 PM, Eric Lee wrote:
> On Wed, Feb 10, 2010 at 7:35 PM, Gunawan Wibisono
> >wrote:
>
> > u should type the error here
> > and attach the file not type in msgbox below
> >
> > what permision for upload folder?
> >
> > On Wed, Feb 10, 2010 at 6:16 PM, Bilal Ahmad <
> > engg.bilalmalik@googlemail.com
> > > wrote:
> >
> > > Hi I am trying to make a form to provide option to user to upload a
> file
> > on
> > > a server.Here is the code for my upload.php. It checks all the
> conditions
> > > etc.. . This code works fine on localhost , and file is uploaded
> > > successfully. But when I use this script online on my server, it gives
> me
> > > error. couldn't figure out what is error.
> > > What I think is error in move_upload_file, but it isn't returning any
> > > error.
> > > File permissions on upload folder are 755.
> > >
> > >
> > >
> > > if((!empty($_FILES['uploaded_file'])) &&
> > ($_FILES['uploaded_file']['error']
> > > == 0)){
> > >
> > > $ok = 0;
> > > $filename = basename($_FILES['uploaded_file']['name']);
> > >
> > > $ext = substr($filename, strrpos($filename, '.') + 1);
> > >
> > > if (($ext == "jpg" || "gif" || "png") &&
> > ($_FILES["uploaded_file"]["type"]
> > > == "image/jpeg" || "image/gif" || "image/png") &&
> > > ($_FILES["uploaded_file"]["size"] < 2097152) ){
> > >
> > > $newname = 'upload/'.$filename;
> > >
> > > if (!file_exists($newname)) {
> > >
> > > if
> > > ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$n ewname))) {
> > > $ok = "1";
> > > echo "It's done! The file has been saved as: ".$newname;
> > > } else {
> > > echo "Error: A problem occurred during file upload!"; //This
> > one
> > > executes when ever i try to upload file on server.
> > > }
> > > } else {
> > > echo "Error: File ".$_FILES["uploaded_file"]["name"]." already
> > > exists";
> > > }
> > > } else {
> > > echo "Error: Only .jpg images under 2MB are accepted for upload";
> > > }
> > > } else {
> > > echo "Error: No file uploaded";
> > > }
> > >
> >
>
> Bilal
>
> hmmm .. Some advice
> is the $_FILES filled correcly
> check if the apache server user able access to the upload folder
> Check if the tmp is writable by apache user
>
>
> Regards,
> Eric,
>
>
>
>
> > Thanks
> > > Bilal Farooq Ahmad
> > >
> >
> >
> >
> > --
> > akan ada dimana mulut terkunci dan suara tak ada lagi..
> > saat itu gunakanlah HP untuk melakukan SMS!!
> > -> ini aliran bedul.. bukan aliran aneh.
> > tertawa sebelum tertawa didepan RSJ..
> >
>
--0015175884b60d5bae047f3dca86--