-3

I know my question might be blocked here but i really cant seem to make up my mind. I am a beginner in Web Development. I am a good designer with HTML CSS AND JQuery but have never worked with server side programming or anything other then pure designing. So i am working on my own website and i have designed everything perfectly. My question is about uploading. I have to allow users to upload a photo and then send it to a particular account of manufacturer for printing. There are only 2 accounts. So just give me an overview of should i use PHP or is JavaScript enough and just name the major concepts when uploading and sending the file on server.

esqew
  • 42,425
  • 27
  • 92
  • 132
  • 1
    Use javascript on the client, PHP on the server. That's typical. – Jonathan M Aug 15 '14 at 19:11
  • PHP is needed to upload files. – jwatts1980 Aug 15 '14 at 19:12
  • This question would be a better fit for http://programmers.stackexchange.com/ – jwatts1980 Aug 15 '14 at 19:13
  • It depends to which manufacturer you are uploading to. It is possible that they offer an API to upload directly to them. Would you mind telling us who those "manufacturers" are? – ihsan Aug 15 '14 at 19:14
  • To handle files on a server, you need a server side scripting language. This can be ASP, PHP or many others, including Javascript, as long as the server supports it. – GolezTrol Aug 15 '14 at 19:15
  • @Ihsan the manufacturers are two local business owners who will have a simple login account listing orders awaiting and delivered. Every order will have a photo with it to be printed. – user3875706 Aug 15 '14 at 19:18
  • 1
    JS cannot upload file . PHP is needed . http://runnable.com/UZKDAYo3XEw2AACX/how-to-upload-a-file-using-jquery-for-php – zod Aug 15 '14 at 19:21
  • http://stackoverflow.com/questions/24168040/upload-multiple-files-with-php-and-jquery/24168617#24168617 – Alexander Ceballos Aug 15 '14 at 20:08

2 Answers2

1

Since you are new to server side programming I assume that you are programming in plain PHP and not using any PHP framework.

Setting up the HTML
In your HTML file you have to setup a form that will allow the user specify a file to upload to the server. When you submit this form, the data (of the file) will be sent (POSTED) to the PHP file specified by you in the form.

Here is a little example of the HTML form (this can be anywhere in your script, I think you are already familiar with these):

<form enctype="multipart/form-data" action="fileprocessor.php" method="post">
     File: <input name="file_up" type="file">
     <input type="submit" value="Upload File">
</form>

fileprocessor.php

<?php

$file_upload  = "true";
$file_up_size = $_FILES['file_up'][size];
echo $_FILES[file_up][name];
if ($_FILES[file_up][size] > 250000) {
    $msg         = $msg . "Your uploaded file size is more than 250KB
     so please reduce the file size and then upload.<BR>";
    $file_upload = "false";
}

if (!($_FILES[file_up][type] == "image/jpeg" OR $_FILES[file_up][type] == "image/gif")) {
    $msg         = $msg . "Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
    $file_upload = "false";
}

$file_name = $_FILES[file_up][name];
$add       = "upload/$file_name"; // the path with the file name where the file will be stored

if ($file_upload == "true") {

    if (move_uploaded_file($_FILES[file_up][tmp_name], $add)) {
        // do your coding here to give a thanks message or any other thing.
    } else {
        echo "Failed to upload file Contact Site admin to fix the problem";
    }

} else {
    echo $msg;
}

There are plenty of tutorials on the web that explains these. I used this as the source for this answer. If you are learning server side programming in PHP, you could try finding video tutorials on YouTube, there are plenty of them.

Good luck.

ihsan
  • 576
  • 2
  • 5
  • 18
0

You would use javascript to allow the user to upload a file, send the file through AJAX to PHP and then PHP would put it into a database.

Maybe let them select the category on the page? so you would have your File and category sent to the server.

Paulo
  • 172
  • 6