In this blog I am going to discuss about how to upload an image in web server. Before you upload an image to the server at first you have to ensure that the web server gives you exact permission to upload the image. If permission is not set to true and you yourself are the web administrator here then you have to set that permission true by yourself. For that you have to use Plesk File Manager (or probably others) for granting permission.
Use the following steps:
1. Open Plesk file manager for web server (provided by Hosting company)
2. Login as administrator
3. Click edit/modify for a folder
4. For all users grant modify permission for the target folder you want to store in your image files.
5. Logout from the Plesk file Manager.
Now comes the user's task to do. He/she has small parts to do. Use the following steps.
1. Drag and drop FileUpload control from toolbox of visual studio. This control has a Browse button. Clicking this button you can select any file and path will be shown in the textbox of this control.
2. If you want to upload just image then you check file extension for images and allow to upload
3. Now look at the following snippet of code (C#).
protected void uploadImage()
{
try
{
string fileName=FileUpload1.FileName;
string serverPath=Server.MapPath("images/"); /*images is the folder in webserver you want to upload images */
if(FileUpload1.HasFile) /*already uploaded to server*/
{
FileUpload1.SaveAs(serverPath+fileName); /*image saved to web server folder*/
}
else StatusLabel.Text="No Image file selected";
}catch(Exception exc)
{
StatusLabel.Text=exc.Message;
}
}
No comments:
Post a Comment