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

Member Avatar for diafol

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

If its very simple then please guide me.
From Step 1.
I have no idea.

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

Member Avatar for diafol

If its very simple then please guide me.
From Step 1.
I have no idea.

Sorry mate, that's not how it works - you gotta have a go yourself first.

The php manual on file uploading is a good start:

http://www.php.net/manual/en/features.file-upload.post-method.php

Come back when you've had a go and need further assistance.

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" />
</form>

For action I use this souce code of PHP

<?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_r($_FILES);

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
        )

)
Member Avatar for diafol

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
        )

)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.