Jump to content

Recommended Posts

hi i am having problem in uploading file can anyone tell me what am i doing wring in the following script

  <form enctype="multipart/form-data" method="post" action="uploadimages.php">
                <input type="hidden" name="MAX_FILE_SIZE" value="20000">
                <div>
                <label class="upload">Choose File:</label>
                <input name="uploadedfile" type="file">
                </div>
                <div>
                <label class="upload">Name:</label>
                  <input type="text" name="name" id="textfield" />
                </div>
                <div>
                <label class="upload">Cover:</label>
                  <input type="text" name="cover" id="textfield2" />
                </div>
                <div>
                <label class="upload">Description:</label>
                  <textarea name="desc" id="textarea" cols="45" rows="5"></textarea>
                </div>
                <div class="actions">
                  <input class="actions" type="submit" name="submit" id="button" value="Upload" />
                </div>
                </form>
                
                <?php
                require("connect.php");
                if(@$_POST['submit'])
                {
                    $name = $_POST['name'];
                    $cover = $_POST['cover'];
                    $desc = $_POST['desc'];
				$file = $_FILES['uploadedfile'];

                    $target_path = "projectimages/";

				echo $name."<br>";
				echo $cover."<br>";
				echo $desc."<br>";
                    
                    $target_path_name = $target_path . basename($file['name']); 
                    echo $target_path_name."<br>";
                    if(move_uploaded_file($file['tmp_name'], $target_path_name)) 
                    {
                        echo "<p><b>The file ".$target_path_name." has been uploaded</b></p>";
                        $insert = "INSERT INTO projectimages (name,description,cover) values ('".$name."','".$desc."','".$cover."')";
					echo $insert;
                        $result = mysql_query($insert);
                    } 
                    else
                        die("There was an error uploading the file, please try again!");
                        
                }
                ?>

Link to comment
https://forums.phpfreaks.com/topic/181384-need-help-in-uploadind-file/
Share on other sites

if(@$_POST['submit'])

if($_POST['submit'])

 

Read through the following.

http://www.tizag.com/phpT/fileupload.php

 

Also code that processes data should be prior to any html. This is always best practice i.e.

<?php
  // process post data
  if($_POST['submit']) {
      // validate
  }
  

  // html
?>
<html>
<body>
<form>
blah, blah, blah
</form>
</body>
</html>

can anyone tell me what am i doing wrong

 

Not until you tell us what symptoms or errors you get. There are at least a dozen different things that could prevent the code you posted from working on your server and with the input you supplied it and unless you state what it does when you try it, no one can tell you which of the possible things is preventing it from working.

 

BTW - The code worked for me. The selected file was uploaded and the INSERT query was formed the way the code intends.

 

Edit: And I have to ask, are you developing and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini to get php to help you by displaying all the errors that it detects? You will save a ton of time. Stop and start your web server to get any changes made to php.ini to take effect and confirm that the settings are actually changed using a phpinfo() statement in case the php.ini that you are changing is not the one that php is using.

can anyone tell me what am i doing wrong

 

Not until you tell us what symptoms or errors you get. There are at least a dozen different things that could prevent the code you posted from working on your server and with the input you supplied it and unless you state what it does when you try it, no one can tell you which of the possible things is preventing it from working.

 

BTW - The code worked for me. The selected file was uploaded and the INSERT query was formed the way the code intends.

 

the if condition does not get true.

it displays else statement i.e, "There was an error uploading the file, please try again!"

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.