Jump to content

[SOLVED] problem with upload form


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



//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);

echo "Error uploading file";
$imagepath = $randName . '.' . $ext;
$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;

//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">
    <textarea name="description" cols="50" rows="7"></textarea>
    <input name="image" type="file" id="image">
    <input name="MAX_FILE_SIZE" type="hidden" id="MAX_FILE_SIZE" value="2000000">
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="Submit2" value="Reset">
    <a href="galleryadmin.php">Back</a></p>

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.

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.