Ajax upload, free PHP script

2012/02/10

I got this question from Tosin ealier this week:

Hello,
Please help with this:
I am using a simple php script to do upload but I want to use your javascript code to display the loading image.

I am ok with my upload script, so I don’t want to use your php class, all I need to do is display the loading image while upload is in progress. How do I customize ur javascript code to do this?

Please help.

Thanks


While this question is not really related to the script in question, the answer is pretty close :) Tosin can use all the Ajax upload tutorial code and need to modify the PHP upload script. The only requirement is that the required response messages are send by the php script. The following example is using some basic upload code from the PHP Manual instead:

<?php
$json['size'] = $_POST['MAX_FILE_SIZE'];
$json['img'] = '';
 
if ($error == UPLOAD_ERR_OK) {
    $tmp_name = $_FILES["fileToUpload"]["tmp_name"][$key];
    $name = $_FILES["fileToUpload"]["name"][$key];
    move_uploaded_file($tmp_name, "$uploads_dir/$name");
    $error = 'Upload OK';
} else {
    $error = 'Upload error';
 
$json['error'] = $error;
echo json_encode($json);
?>

Leave a Reply

Your email address will not be published. Required fields are marked *