Jump to content

[SOLVED] problem with upload form


wrathican

Recommended Posts

the code below is meant to determine whether or not a file has been set to transfer

 

the problem i have is that it doesnt upload the file

it returns me back to the form... so that tells me that the file isnt gettin sent

 

can someone have a look and suggest any help?

thanks in advanced

 

<?php

//addalbum.php included into galleryadmin.php

//if $_POST is set then upload file and add data to DB
//else show the form to add a new album
if (isset($_POST['image']) && $_POST['image']['size'] <= 0)
{
//upload file and add to db

$fileName = $_FILES['image']['name'];
$tmpName = $_FILES['image']['tmp_name'];
$description = $_POST['description'];
$albumname = $_POST['title'];

// get the file extension first
$ext = substr(strrchr($fileName, "."), 1);

// make the random file name
$randName = md5(rand() * time());

// and now we have the unique file name for the upload file
$filePath = '..images/gallery/' . $randName . '.' . $ext;

$result = move_uploaded_file($tmpName, $filePath);

if(!$result){
echo "Error uploading file";
exit;
}
$imagepath = $randName . '.' . $ext;
if(!get_magic_quotes_gpc())
{
$albumname = addslashes($albumname);
$imagepath = addslashes($imagepath);
$description = addslashes($description);
}
$query = "INSERT INTO cy_album (al_name, al_description, al_image ) ".
"VALUES ('$albumname', '$description', '$imagepath')";

mysql_query($query) or die('Error, query failed : ' . mysql_error()); 

echo $query;

}else{
//show form
?>
<form action="galleryadmin.php?func=addalbum" method="post" enctype="multipart/form-data" name="form1">
  <p>Album Title:<br>
    <input type="title" name="textfield">
    <br>
    Description:
    <br>  
    <textarea name="description" cols="50" rows="7"></textarea>
    <br>
    Image:
    <br>
    <input name="image" type="file" id="image">
    <input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="2000000">
    <br>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="Submit2" value="Reset">
    <br>
    <a href="galleryadmin.php">Back</a></p>
</form>
<?php
}
?>

Link to comment
Share on other sites

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.