Uploading Files

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
AaaDee
New php-forum User
New php-forum User
Posts: 25
Joined: Mon Jun 24, 2002 1:10 am
Location: Huddersfield
Contact:

Uploading Files

Postby AaaDee » Tue Jul 16, 2002 4:44 am

Ok, whats wrong with this, it ONLY uploads jpg files, i thought i was the daddy at first but it only works for jpgs, want it to work for ALL of the files!!!!

<?

if (is_uploaded_file($attach) != '')

{

copy($attach, "Uploads/$attach_name");

}

?>

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Re: Uploading Files

Postby Oleg Butuzov » Tue Jul 16, 2002 4:56 am

AaaDee wrote:Ok, whats wrong with this, it ONLY uploads jpg files, i thought i was the daddy at first but it only works for jpgs, want it to work for ALL of the files!!!!

Code: Select all

<?

if (is_uploaded_file($attach) != '')

{

copy($attach, "Uploads/$attach_name");

}



?>



may be...

Code: Select all

<?
if (is_uploaded_file($attach))
{
copy($attach, "Uploads/$attach_name");
}

User avatar
AaaDee
New php-forum User
New php-forum User
Posts: 25
Joined: Mon Jun 24, 2002 1:10 am
Location: Huddersfield
Contact:

nope

Postby AaaDee » Tue Jul 16, 2002 5:02 am

afraid not! just the same.

Adam

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: Uploading Files

Postby WiZARD » Tue Jul 16, 2002 5:08 am

AaaDee wrote:Ok, whats wrong with this, it ONLY uploads jpg files, i thought i was the daddy at first but it only works for jpgs, want it to work for ALL of the files!!!!

<?

if (is_uploaded_file($attach) != '')

{

copy($attach, "Uploads/$attach_name");

}

?>


Hi there!
It's most popularity mistakes of beginner programmer on PHP.
And will best if you using file size.... etc.
Cause PHP and MIME working together.

Code: Select all

<form enctype="multipart/form-data" action="_URL_" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">
</form>

See this code, and try make some like this (from manual of PHP).

or this:

Code: Select all

<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILES  should be used instead of $_FILES.
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
    copy($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
} else {
    echo "Possible file upload attack. Filename: " . $_FILES['userfile']['name'];
}
/* ...or... */
move_uploaded_file($_FILES['userfile']['tmp_name'], "/place/to/put/uploaded/file");
?>
Last edited by WiZARD on Tue Jul 16, 2002 5:13 am, edited 1 time in total.

User avatar
Oleg Butuzov
Last Samuray
Last Samuray
Posts: 831
Joined: Sun Jun 02, 2002 3:09 am

Postby Oleg Butuzov » Tue Jul 16, 2002 5:13 am

Code: Select all

<?
if (is_uploaded_file($attach))  // if you trensfer file and file exist this runction return - TRUE
{
// and this code will execute
copy($attach, "Uploads/$attach_name");
}
>


may be you have error in the other plece of your script...[/code]


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron