Jump to content

[SOLVED] erroring on file upload script


Ryoku

Recommended Posts

I'm tinkering with file uploading on a DB on my computer before i risk destroying on on my server

 

currently I have the fallowing script written but it give me an error (probibly more knowing my horrid typeing) though i can't seem to figure out what I messed up on this.

 

I'm losely fallowing a tutorial found : Here since the one i did from Here worked well enough for me.

 

I'm trying to rename the file uploaded and move it to a folder which was successful in the last incarnation of this script (at least moving it w/o renaming it. as it sits rite now I'm getting an error from my script and I can't seem to figure out how to fix it. I'm pretty sure its because something wasn't declared correctly but I can't see it. I've been farting with this for the past 5 hours and I think a fresh set of eyes could help this out (considering I've been up for the past 30)

 

<?php
/*list of recived variables from Fuploader.php

Var       Var is        SQL
________+_____________+________________
GalDate - the date    = date
GalTLT  - title       = title
TMPfile - the file    = url
GalCMT  - the comment = comment                   */

//declairing short variables

$oldname = $_FILES['TMPfile']['name'];                    //input file
$path= "../fauxgal/";                                            //path to final resting place
$postid  = $row['postid'] + 1;                                //needs database access
$fileEXT = substr($oldname, strripos($oldname, '.')); //getting extension
$newname = date(Ymd) . $postid . $fileEXT;           //declairing new file name eg."20080808-00001.jpg"
$db      = 'webserv';

//--------------------------------------------------------------------------------------------------------//
// variables for db server
$date    = $_POST['GalDate']; // phraseing the posted variables
$title   = $_POST['GalTLT'];
$coment  = $_POST['GalCMT'];


//this block connects to the DB to get the post id for file name
$con = mysql_connect('localhost','','');
if(!$con){
  echo "There was a problem: " . mysql_error();
}else{
  mysql_select_db($db,$con);
  $result = mysql_query("SELECT postid FROM gallery ASC LIMIT 1");
  $row    = mysql_fetch_array($result);
  GLOBAL $row;
}// end DB query for file name

$rename  = $path . $newname;
$path    = $path . $rename;
if($oldname != none){
  if(copy($oldname,$path))     //<-----line 43
  {
    
    ?>
<div style="width:300px;border:1px solid #000000;">
  <?php
    echo ('File /" ' . $oldname . '/" moved and renamed to /" ' . $newname . '/" Sucessfuly!');
    echo ('<br //><img src=/"' . $path . '/" //>');

    echo ("Title/: " . $title . "<br //>");
    echo ("<hr />");
    echo ("Comment/: " . $coment);
  }else{
    echo "Echo There was an error!";
  }
  }
  
  mysql_close($con); //close mysql link
  
?>
</div>

 

currently i'm getting the fallowing error (image named "blank_sample.jpg" and is just a vertical image with the word "blank in it"):

 

Warning: copy(blank_sample.jpg) [function.copy]: failed to open stream: No such file or directory in C:\webserver\content\testscripts\fhandeler.php on line 43

Echo There was an error!

 

thank you in advance for anyone who contributes ^^

 

Ryoku

 

p.s. (I know its probibly not very efficent to get the postid from the DB but I'll be storing the URL in the DB anyway so might as well open it =P )

Link to comment
Share on other sites

I managed to figure it out on my own after stairing at the function for a while. I don't think copy was the rite function to use. i used a move_uploaded_file() function and change the original file (['TMPfile'],['name']) to the name of the temp file (['TMPfile']['tmp_name']) and cleaned up some of those confusing variables to rename the file.

 

if someone is looking at this as reference change the code as fallows:


//from
$rename  = $path . $newname;
$path    = $path . $rename;
if($oldname != none){
  if(copy($oldname,$path))     //<-----line 43
  {

//to

$path    = $path . $newname;
if($oldname != none){
  if(move_uploaded_file($oldname,$path))     //<-----line 43
  {

 

remove the line that says $rename and change the $rename var to $newname and change copy() to move_uploded_file()

 

and its good!

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.