file upload fail in php - php

When I put this:
<input name="image" type="file" value="Browse" />
I get a weird text in hebrew..saying "choose file" and next to it is written "file wasnt chosen", how do I make the text in english..how do I override the default?
Also how do I put a predetermined picture in my database.. do I go to a field and click As defined than put :
"Images/Untitled-1.png"
The image folder than the image name?

Check your localization settings....no overriding here, it's the OS that does this for you.

Related

Is there some way to change the default setting from All Files in the file upload dropdown?

I'm currently building a file upload method for a client that's going to be used by small children, so we're trying to eliminate as much room for error as possible. Is there a way I can change the default setting of the file upload dropdown from All Files to the filetypes we're allowing on the page? We've already got measures in place to keep users from uploading non-allowed files, this is just to make it extra clear so users don't waste time accidentally selecting the wrong filetype. Example:
I'd like to have the field the arrow is pointing to automatically show, say, .jpg and .pdf instead of All Files, for example.
Use the accept attribute of the input tag. So to accept only PNGs, JPEGs and GIFs you can use the following code:
<input type="file" name="myImage" accept="image/x-png,image/gif,image/jpeg" />
Or simply:
<input type="file" name="myImage" accept="image/*" />
Note that this only hits the browser to accept this code. I. E. Opera and ie9 does not support this
You can use the accept attribute on the <input> field:
<input type="file" … accept="image/png, image/gif">

editing file not taking default value=image_name

View
<form class="m-form" action="<?php echo AURL;?>products/update_product/<?php echo $products['product_id'];?>" method="post" enctype="multipart/form-data">
<input type="file" name="product_image_name" class="form-control m-input dropify" placeholder="" data-default-file="<?php echo Website_Assets.'images/'.$products['product_image_name'];?>" value="<?php $products['product_image_name'];?>" data-max-file-size="2M" required>
</form>
In above code product_image_name not taking any value but showing the image picking the path and when I change image it post the image_name
Controller
public function update_product($product_id)
{
echo "<pre>";
print_r ($_FILES['product_image_name']);
echo "</pre>";
exit();
}
changing the image works ok but if i donot change image its not picking the default value of the image
Short answer: An input of type file can not have a default value.
Instead use an <img />-tag to show default images. For example:
<img src=" <?php echo Website_Assets.'images/'.$products['product_image_name'];?>" />
Normal answer: Assuming you are trying to upload an image, save it to the entity that is behind the form and later edit it; try to think around using just the one field. Instead perhaps a sequence like this:
Upload a file using the upload field
Save the uploaded file on the machine that runs PHP (server-side)
Store the path to the uploaded file in the entity
In the edit view of the entity show both:
the image that was uploaded (or a placeholder)
an upload field to upload a new image
Good luck!
Tip: You might also want to have a look at open source libraries like dropzonejs. Existing libraries often give examples and excellent documentation. This example visually combines the upload field with the display field.

How to upload .ipa file to server in html?

I am able to upload other file types like .txt, .png, .apk using
<form action="index1.php" method="post" name = "mySuperForm"
enctype="multipart/form-data">
<input type="text" placeholder="Application Name" name="appname">
<input type="text" placeholder="Version Number" name="appversion">
Application File: <input style = "width:auto" type="file" name="file" id="file"><br>
</form>
But, when I try to upload a .ipa file, I can't grab the application name or version number on index1.php (the page I am posting to)using $_POST. However, if I upload a different file type, I can. It's as if nothing is getting posted if I try to upload an ipa file, like the html is failing on that line. I am using my localhost, wamp server. Any advice?
Without seeing your handling PHP, it's a bit difficult to diagnose, but here are a few potential items that may point you in the right direction:
Does the .IPA file exceed the *post_max_size* or *upload_max_filesize* as defined in your PHP configuration?
Try var_dump($_FILES); to see if your script is seeing the files there.
I think this is happening because the file is too big and the request is being truncated by the web server, so PHP would not be able to access any form fields because the request was not completed. How large is the ipa file? You might need to adjust your maximum post size. The default is usually 4 MB.

How can I download an image based on a url in PHP? curl?

I have used a input file code to upload image to my wallpaper site..
<input type="file" name="img" id="img" />
Is there anyway to select a image without selecting image file..like entering URL to text box?
<input name="img" type="text" id="img" value="http://www.somesite.com/image.my.jpg" size="40" />
I tried its not working...please help me! Anyway to enter image url to text box except select browse button and selecting image file? help me i tries in different ways...
Is there anyway to user type="text" excepts type="file" so We can enter image url in that text box and upload?
With that <input> you then have to tell your PHP code to go and download that file e.g.
<?php
if (!empty($_POST['img'])) {
file_put_contents('savedImage',file_get_contents($_POST['img']));
}
However doing so opens you up to some potential security issues, so be careful!
I think what you want to do is upload an image and then display that on a page.
You need to move the image into a folder on your webserver then display that output.
More info about it here.

HTML form for PHP file upload: no textbox

My PHP book gives a template HTML form for uploading a file:
<form action="upload.php" method="post" enctype="multipart/form-data"/>
<div>
<input type="hidden" name="MAX_FILE_SIZE" value="10000000"/>
<label for="userfile">Upload a file:</label>
<input type="file" name="userfile" id="userfile"/>
<input type="submit" value="Send File"/>
</div>
</form>
The book displays it as "Upload a file:" [textbox] [Browse...] [Send File]
I copied it verbatim, and the result I'm getting is "Upload a file:" [Choose File] "no file chosen" [Send File]
I'm wondering why the discrepancy exists. Is there a way around it? I'm using XHTML Transitional. No doctype is given in the book. But I doubt that's the issue.
The script I'm writing aims to take the file the user chooses, process it, and write the result into another file that doesn't exist yet. I'm asking this question because it would be useful to let the user more easily copy the initial file path/name, paste it into the other field, and just change a part of it.
(Also: why the difference between "Browse..." and "Choose File"? I tried manually setting the value of the "userfile" field to "Browse..." but nothing happened. This is less important but I'm curious nonetheless.)
It is probably showing a different browser and/or version.
It sounds like you are looking at it under Safari and the book has screenshots of IE, for example.
There are a few ways to get complete control of file uploading and the <input type="file" /> element. You can use Flash, or you can set the input to opacity: 0 and then position what you want beneath it.
Some time ago the browser engines took almost complete control over the input type="file" - fields, since it nowadays is regarded as a security issue. For example the days before that you could easily prefill the file input filed with some path and filename (e.g. something like /etc/passwd) and hide the field, so sending the form you would not remark that you're also sending the file...
That's why for example you could not preset the filename of such a field and that's also why browsers now all do their own thing with these special input fields.
As Alex said above, you could get around this, but it will be some hassle, because it would mean to "fake" the file input field.

Categories