Jump to content


Photo

file upload error


Best Answer jazzman1, 17 May 2013 - 01:13 PM

Did you restart apache?

Go to the full post


  • Please log in to reply
17 replies to this topic

#1 Jaswinder

Jaswinder

    Advanced Member

  • Members
  • PipPipPip
  • 127 posts

Posted 14 May 2013 - 09:41 PM

hi.. the code i am using for uploading is working fine few days back.. now giving some errors.. please solve it

 

<form action="up1.php" method="post" enctype="multipart/form-data">
<input type="file" name="up" />
<input type="submit"  value="submit"/>
</form>

 

 

php

 

<?php
$up=$_FILES['up']['name'];
copy($_FILES['up']['tmp_name'],"upload"."/".$up)
?>

 

where upload is a folder in which all the uploaded files are stored

 

Error - -  Warning: copy(): Filename cannot be empty in C:\xampp\htdocs\copy\up1.php on line 3

 

where is the mess ???

 



#2 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 720 posts
  • LocationEarth

Posted 14 May 2013 - 10:08 PM

Your file is missing/not pointed to the right name of the file.


Edited by Q695, 14 May 2013 - 10:09 PM.

if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#3 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,700 posts

Posted 15 May 2013 - 04:36 AM

your code is not testing if the upload worked before using the uploaded file. try this - 

if($_FILES['up']['error'] === 0){
    // upload worked without any error
    $up=$_FILES['up']['name'];
    move_uploaded_file($_FILES['up']['tmp_name'],"upload"."/".$up);
} else {
    // upload failed, do some debugging
    echo 'Upload failed.';
    echo '<pre>';
    print_r($_FILES);
    echo $_SERVER['CONTENT_LENGTH'];
}

multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#4 Q695

Q695

    Advanced Member

  • Members
  • PipPipPip
  • 720 posts
  • LocationEarth

Posted 15 May 2013 - 11:14 AM

Adapt these videos:


if ($problem==mark_solved){

solution ($problem);}

 

if ($skill_level==learning && $my_knowledge==the_required_level_of_knowledge){

     echo "I will try to help, because you're still $skill_level , and my skill level is at $my_knowledge";

} else {

     echo "I can't help you, go away.";

}


#5 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,700 posts

Posted 15 May 2013 - 08:51 PM

@Q695,

 

sorry to pick on more of your replies, but the OP already has an upload script. he needs help finding out why it produces an error when trying to copy the uploaded file. posting a link to an upload tutorial with code that is no better than what the op has now, isn't specific to the problem.


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#6 Jaswinder

Jaswinder

    Advanced Member

  • Members
  • PipPipPip
  • 127 posts

Posted 15 May 2013 - 09:38 PM

thanks for your answers.....

 

i came to know my tmp_name is coming empty..but dont know why...

 

any solutions?? how to fix this??



#7 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,700 posts

Posted 15 May 2013 - 10:03 PM

the code i posted in reply #3 would have helped determine why the tmp_name is empty. did you try that code?


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#8 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 15 May 2013 - 10:22 PM

None of the answers above are corect b/s of lack of server side knowledge.

 

So, the copy php function is a simple and it's works only if the file already exist on the machine (server).

 

When you try to upload a file from a local machine to the server the file is saved as a tmp, that's why mac_gyver proposal is correct to use move_uploaded_file ().


Edited by jazzman1, 15 May 2013 - 10:25 PM.


#9 Jaswinder

Jaswinder

    Advanced Member

  • Members
  • PipPipPip
  • 127 posts

Posted 16 May 2013 - 10:13 AM

yes @ mac_gyver

 

i tried your code ... it is working fine for all files except for any  songs    and   videos..

 

following error is coming

 

 

Upload failed.

Array
(
    [up] => Array
        (
            [name] => filename.mp3
            [type] => 
            [tmp_name] => 
            [error] => 1
            [size] => 0
        )

)
6511567

is there any other method for mp3 or mp4

files ??



#10 mac_gyver

mac_gyver

    Advanced Member

  • Administrators
  • 2,700 posts

Posted 16 May 2013 - 10:26 AM

the problem isn't the method. you are getting an upload error due to the size of the file and your php settings. see this link - http://uk.php.net/ma...load.errors.php


multi-purpose programming fool. well written source-code should be self-documenting. well written code should be self-troubleshooting. 


#11 Jaswinder

Jaswinder

    Advanced Member

  • Members
  • PipPipPip
  • 127 posts

Posted 17 May 2013 - 07:11 AM

how u came to know its a maxsize problem not of type or tmp_name as they are also coming blank ??

 

and also in php.in i changed max_upload_size still getting same error.... any other changes needed??



#12 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 17 May 2013 - 07:36 AM

Check this thread, especially my last post it would help you I guess. 



#13 Jaswinder

Jaswinder

    Advanced Member

  • Members
  • PipPipPip
  • 127 posts

Posted 17 May 2013 - 01:03 PM

my php.ini shows this

 

;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
; http://php.net/file-uploads
file_uploads=On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://php.net/upload-tmp-dir
upload_tmp_dir="C:\xampp1\tmp"

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize=2M

; Maximum number of files that can be uploaded via a single request
max_file_uploads=20

 

 

 

i changed upload_max_filesize=2048M  but still same error



#14 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 17 May 2013 - 01:13 PM   Best Answer

Did you restart apache?



#15 Jaswinder

Jaswinder

    Advanced Member

  • Members
  • PipPipPip
  • 127 posts

Posted 17 May 2013 - 01:32 PM

:) thank you again .... problem solved ..

 

i more question.. how this problem  will be solved if same problem arises after uploading my website on hosting



#16 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 17 May 2013 - 01:46 PM

The easiest way is to create a custom php.ini file which overridding the main php.ini file from the server, or to use ini_set setting new values.  

 

EDIT: The other way is to hack the server :)


Edited by jazzman1, 17 May 2013 - 01:52 PM.


#17 Jaswinder

Jaswinder

    Advanced Member

  • Members
  • PipPipPip
  • 127 posts

Posted 17 May 2013 - 02:04 PM

:) i think 1st option is better..

 

so how to create custom php.ini file

Is i have to copy my local  php.in and where to paste it... and how it will override the main php.ini



#18 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,678 posts
  • LocationMississauga, Canada

Posted 17 May 2013 - 02:13 PM

:) i think 1st option is better..

 

so how to create custom php.ini file

Is i have to copy my local  php.in and where to paste it... and how it will override the main php.ini

 

That depends of your hosting provider, just check the helping guide manual that they provide to their customers.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com