I'm new to PHP, but I usually program Windows Apps in .NET(c#, VB). So please excuse my unfamiliarity with code and HTML combined.
It seems pretty simple to upload a file to a website using the following html: - <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="">
-
<p><input type="file" name="image_file" size="20"></p>
-
<p><input type="submit" value="Upload Image" name="action"></p>
-
</form>
I'm dealing with a website that the standard is not to use separate script files, but to code in the same file as the html. Most examples on the web for this use separate script files. I found a few examples that do not work. What am I missing in my code to somehow connect the uploaded file in the html to my code on top?
My code with html: - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
-
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt.php" codeOutsideHTMLIsLocked="false" -->
-
-
<head>
-
<script type="text/JavaScript">
-
-
<? php
-
-
define ('MAX_FILE_SIZE', 1024 * 50);
-
-
if (array_key_exists('upload', $_POST)) {
-
// replace any spaces in original filename with underscores
-
$file = str_replace(' ', '_', $_FILES['image']['name']);
-
// create an array of permitted MIME types
-
$permitted = array('image/gif', 'image/jpeg', 'image/pjpeg',
-
'image/png');
-
-
// upload if file is OK
-
if (in_array($_FILES['image']['type'], $permitted)
-
&& $_FILES['image']['size'] > 0
-
&& $_FILES['image']['size'] <= MAX_FILE_SIZE)
-
{
-
$result= "$file file uploaded!";
-
}
-
else {
-
$result = "$file is either too big or not an image.";
-
}
-
-
-
}
-
?>
-
-
-
-
</script>
-
</head>
-
<body>
-
-
<?php
-
// if the form has been submitted, display result
-
if (isset($result)) {
-
echo "<p><strong>$result</strong></p>";
-
}
-
?>
-
-
<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="">
-
<p><input type="file" name="image_file" size="20"></p>
-
<p><input type="submit" value="Upload Image" name="action"></p>
-
</form>
-
-
</body>
-
</html>
Thanks!
5 1991 code green 1,726
Recognized Expert Top Contributor
I think what you are trying to do is get the same page to submit itself.
You do this with - action="$_SERVER['PHP_SELF']"
I'm getting the following error:
Firefox can't find the file at
/C:/WebSites/STUNNI~1/$_SERVER['PHP_SELF'], the root directory being the root of my page. Why does it think it's a separate file? Am I missing something important in my code on top?
code green 1,726
Recognized Expert Top Contributor
I think your HTML is wrong. I would need to see it.
But $_SERVER['PHP_SELF'] returns
The filename of the currently executing script, relative to the document root.
For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar.
If it's in HTML, then he needs to do:
action="<?php echo $_SERVER['PHP_SELF']; ?>"
That should work.
In the end, I think the problem was that I wasn't running it from the proper place- from my localhost (or my WAMP/www directory. I was just running it from my regular file directory. Not sure if this makes sense, but I'm not getting the error anymore. Thanks for your help!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: balgach |
last post by:
Greetings all,
I have a group of rather large files (by group i mean close to 2x10^7
files, each 12-15megs) now i need information which is stored in just
the last 512 bytes of each file. i was wondering if there is a way to
strip out this information without loading the entire file into memory.
Right now im doing it with fopen() and fread() and it takes several
hours to process all the files. obviously i know exactly where the...
|
by: ulyses |
last post by:
Let's assume I have following file:
2938929384902491233.....
923949919199191919112....
File contains INTs only. What is more they are huge. For example first
row in file may contain integer which size is 50MB and the second 30MB.
Now we come to my problem. Is there possibility to swap this rows
without using system memory (preferably in Unix/Linux)? Is there any
function in C to do this?
|
by: gsuns82 |
last post by:
hi friends,can any one give the coding for finding file size
using java script???
|
by: sat |
last post by:
Hi,
I'm working as a DB2 UDB DBA.
I have some questions regarding SCP command...
Actually every week redirect restore takes place from one of my
production servers to test servers..
So, but before i can restore it on the test server i need to transfer
the backup file from the production server... So i want use the SCP
command to do that... since it takes place on every wednesday early
morning i would like run the scp command using...
|
by: rinkudhimar |
last post by:
I want to write using fwrite and upload the file without using File Field or Browse option. Actually I want to upload static file after writing it useing fwrite and as soon as it gets uploaded it should be savedt o the database.I want code for this:
1)
Write a file
2)
Upload the same file(static one)
3)
Save it to Database
| |
by: ganesh.kundapur |
last post by:
Hi,
I want to know how to compile the C source file without using the
compiler directly. I mean to say by using compiler componets such as
( cpp, cc, as, ld ).
I tried to compile the fallowing code as fallows
file name: hello.c
# include <stdio.h>
int
main ( void )
|
by: Gorksha |
last post by:
How to upload a file without using browse button provided by
<input type=file > tag in html..
|
by: Kuldeep |
last post by:
Framework: Visual Studio 2005
Technology: ASP.NET 2.0
Language: C#.NET 2.0
Hi All,
How can we generate an Excel File through C#.NET without using Interops or
XML ?
Any leads on this would be highly appreciated.
|
by: mihir0288 |
last post by:
I want to save HTML file that i open in web browser on my hard disk without using save file dialog box. I want to save it as html page through only code and without user interactions.
|
by: nguyenthuy |
last post by:
How to disable Mousewhell without using MouseWheel.dll file and copy it to each computer need to prevent scrolling.
If there are many computer use the program, I can't setup one bye one.
So, please support me!
Thanks
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |