Hi, Its Ayesha, I am new to PHP and MYSQL , I am working on a Project in which I have to give rights to one user to UPLOAD a JPEG picture Using Browse . So Any one can Help? I want to store my JPEG Files in a Folder Names MYJPEG in Server.
Thanks in Advance....:)

9 Years
Discussion Span
Last Post by diafol

This is a fairly basic pHp routine. Show what you've got so far and we'll guide you along.


well i did the same in asp
used a script that was available on net
if you want i can tell you..but then its in asp


Hi I have found this code.
Now what I can Write in action?

Here is a code

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />

For action I use this souce code of PHP

// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";

echo 'Here is some more debugging info:';

print "</pre>";


But it gives following erros.

Warning:  move_uploaded_file(/other/my.html) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\other\upload.php on line 17

Warning:  move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php43.tmp' to '/other/my.html' in C:\xampp\htdocs\other\upload.php on line 17
Possible file upload attack!
Here is some more debugging info:Array
    [userfile] => Array
            [name] => my.html
            [type] => text/html
            [tmp_name] => C:\xampp\tmp\php43.tmp
            [error] => 0
            [size] => 1057


OK 2 things - firstly make your max filesize greater than 30000, or you'll get an error (#= 2).

Secondly, why are you using "var/www/uploads" ? I assume you're on a local webserver. If so, use this as your uploaddir: $uploaddir = $_SERVER['DOCUMENT_ROOT'] . "/uploads/"; which takes it that you've created a folder called uploads under root.

Here's what I got from your code after making those changes:

File is valid, and was successfully uploaded.
Here is some more debugging info:Array
    [userfile] => Array
            [name] => Y gwaelod sy.doc
            [type] => application/msword
            [tmp_name] => C:\xampp\tmp\php4F58.tmp
            [error] => 0
            [size] => 598528

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.