Jump to content

file upload error


Jaswinder
Go to solution Solved by jazzman1,

Recommended Posts

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 ???

 

Link to comment
Share on other sites

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'];
}
Link to comment
Share on other sites

@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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 ??

Link to comment
Share on other sites

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

Link to comment
Share on other sites

:) 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.