Brandyn
Brandyn

Reputation: 1017

Uploading image directory

I am attempting to upload an image directory to a MySQL table. I upload the image to a folder through PHP and what I had planned on doing was to copy the directory of the file to the table where it can be used by another page on the website. However, upon first visit to the page, I get this error:

SCREAM: Error suppression ignored for ( ! ) Notice: Undefined variable: file in C:\wamp\www\Website\newproject.php on line 125 Call Stack #TimeMemoryFunctionLocation 10.0011726560{main}( )..\newproject.php:0 uploads/upload_"/>

I know what this error is caused by, however I was wondering if there was a way to immediatley have the file name inserted into hidden input field here:

<input type="hidden" name="projectPhoto" value="<?php $location = "uploads/upload_".$file; 
                                                                    echo "$location";
                                                                ?>"/>

The $file variable is the file/image name.

So basically as the file input button is clicked, that variable or location is then immediately placed into the hidden field. What is the best way of doing this?

It should also be noted that upon trying to upload an image when this error is on, I simply get the actual PHP error uploaded into my database. After this however, I am able to upload image directories without a problem.

Upvotes: 2

Views: 113

Answers (1)

TSkagen
TSkagen

Reputation: 67

When sending variables from PHP to JS use something like this:

<button id="add" onclick = "functionName('.$var.')">TEXT</button>


function functionName(a)
{   
   alert(a); //Just to check    
}

Upvotes: 1

Related Questions