Starting new thread here for the issue.
Hi everyone.
I am having the problem in PHP file upload [a simple text file having string "hello world"].
Its works fine with other browser like Google Chrome, IE, etc.
But having problem in FF browser. getting "The connection was reset" error.
Anyone knows whats happening here? any help would be appreciated.
Here is the usecase -
I.e - I have a page say page1.php - in this page I am having a simple html file upload tag -
Page1.php
<html>
<body>
<form enctype="multipart/form-data" name="testF" id="testF"
action="upload.php" method="post">Enter file:<input
type="file" name="tfile" id="tfile" /> <input type="submit" name="sub"
id="sub" value="Upload" /></form>
</body>
</html>
upload.php -
I this file I am just printing the $_FILE array.
<?php
if(isset($_POST['sub']))
{
echo("Sub clicked, got in!");
echo("<pre>");
print_r($_FILES);
}
else
{
echo "File is not uploaded";
}
?>
Update -
This works absolutely fine on development environment [Local machine]. Issue is on production server.
I have the following problem:
On a website I'm coding for a client I have a form where you can upload images (up to 5, seperate file-input elements (so no problem caused by a flash / javascript solution)).
But sometimes the upload fails directly (nearly instantly the "Page cannot be displayed"-page is shown) or the request does not contain the files.
This is not an issue of file-size (as it happens sometimes, no matter if the files are larger (~2-3MB) or really small (150kB)) or request timeout (as the upload fails directly and not always - but too often ;-)).
Another weird thing: I tried to analyze the whole thing using Fiddler. But while using Fiddler the problem simply does not occur.
Any ideas?
Tested in IE9/10 on Win7/8
Chrome, FF etc. work fine, of course ;-)
/edit: I use a really simple test script (fails like the regular webapp)
<?='<!DOCTYPE html>'?>
<html>
<head>
<title>Upload Test</title>
</head>
<body>
<form action="http://www.site.com/upl-test/index.php" method="post" enctype="multipart/form-data">
<input type="file" name="img_file0" />
<input type="file" name="img_file1" />
<input type="file" name="img_file2" />
<input type="file" name="img_file3" />
<input type="file" name="img_file4" />
<input type="submit" name="submit_btn" value="Upload" />
</form>
<?php
if(!empty($_FILES)){
echo '<hr /><pre>';
var_dump($_FILES);
echo '</pre>';
}
?>
</body>
</html>
So i made use of this guide and was able to come up with this:
<html>
<head></head>
<body>
<form action="process.php" method="get">
<input type="text" name="image"/>
<input type="submit"/>
</form>
</body>
</html>
and process.php i came up with:
<?php
include("SimpleImage.php");
$imgName = $_GET["image"]; //assuming you used GET request and form submits to http://url/script.php?image=something.jpg
$image = new SimpleImage();
$image->load($imgName);
$image->resizeToWidth(250);
$image->save($imgName);
echo $imgName;
?>
However something's wrong. It's not saving the image :( I'm completely a PHP noob so i hope you can give some newbie friendly solutions. Thank YOu :)
check your folder/file permission if you are able to read/write on that directory.
If you have not set a path on where to save the new image, usually it writes to the same directory where your process.php is located.
I'm developing an image host and wish to have images uploaded to a separate server from my web content, eg: http://i1.mysite.com instead of http://mysite.com/uploads. But I'm having some trouble figuring out how to do that.
Say I have this form:
<form action="http://mysite.com/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="image" id="file_upload" />
<input type="submit" value="Upload" id="upload_submit" />
</form>
That will send an image file to /upload, where I can validate the file and save it, but that will be on the same server as the website is hosted, rather than a dedicated storage server. How can I achieve what I want without having the images uploaded on the same server as my web site?
I could always do:
<form action="http://i1.mysite.com/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="image" id="file_upload" />
<input type="submit" value="Upload" id="upload_submit" />
</form>
which would send the image file to another server, but then when the image upload is complete I'd be redirected to http:/i1.mysite.com/upload.
Anyone have any experience with this and can recommend a course of action? Thank you!
Don't upload to the image server. Such content-specific servers should be optimized for serving up content, and not have to deal with consuming content.
Let the upload form send to your main site's server. You can then use other protocols to transfer the uploaded file(s) to the image servers. rsynch, scp, etc... This way you have all your "control" code in one location, and don't have to worry about synching databases and whatnot between multiple servers - all the data is kept on your main server, and the image servers just passively spit out image data.
I would recommend decoupling these two ideas. First, upload the image to your servers and in a separate process (perhaps a scheduled cron) move the images to other server. You likely do not want the user waiting for two uploads to finish.
Like the others have said, what you're trying to do is not optimal. If you really want to continue to do this, I'd suggest having the form submit to a PHP script which then processes it and places the file where it needs to be and then saves whatever information to the database that is necessary. You'll need to evaluate the best protocol for the data transfer from one server to the other. You'll probably end up using Curl, which you can learn about here and here as well as the curl docs
You could upload the image to your image host, and have it redirect back to your website afterward. One way to do this would be to add hidden "success" and "failure" URL inputs to the form:
<form action="http://i1.mysite.com/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">
<input type="file" name="image" id="file_upload" />
<input type="submit" value="Upload" id="upload_submit" />
<input type="hidden" name="success" value="http://mysite.com/success" />
<input type="hidden" name="failure" value="http://mysite.com/failure" />
</form>
The upload script on your image host would then redirect to the supplied URL after a successful upload:
<?php
.. handle uploaded file ..
if ($success) {
header ('Location: ' . $_REQUEST ['success']) ;
}
else {
header ('Location: ' . $_REQUEST ['error'] . '?message=' . $message) ;
}
?>
I've made a simple form, with the proper enctype for uploading files. When i try to upload a .docx everything works fine in IE 8 and Safari, but in Firefox or IE 7 or 6 i can't even click submit, nothing happens! Could this still be a server issue? It's an apache server.
Everything works fine if i choose to upload a .doc file
<form enctype="multipart/form-data" method="post" action="index.php">
<input name="file" type="file" />
<input type="submit" name="btnSubmit" value="Submit"/>
</form>
I tested your form in my Wamp2.0 with IE7 and Firefox,and it works fine.I don't think it could be the server issue since the form works well in you IE8.Perhaps you should standardize your html code,or check you browsers.