A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: php script error

Hybrid View

  1. #1
    Senior Member
    Join Date
    Nov 2004
    Posts
    286

    php script error

    I am using a free script from hotscripts for multiple file uploads....I uploaded all files to server and tried it, and this is the error I get:

    Warning: move_uploaded_file(naturaltalent.cc/xml2/files//signed.jpg): failed to open stream: No such file or directory in /hsphere/local/home/naturalt/naturaltalent.cc/xml2/uploader.php on line 116

    Warning: move_uploaded_file(): Unable to move '/tmp/phpM2CkCe' to 'naturaltalent.cc/xml2/files//signed.jpg' in /hsphere/local/home/naturalt/naturaltalent.cc/xml2/uploader.php on line 116


    here is the php code from the script:

    <?
    /*
    Multifile Uploader Script - Copyright © Teletone [Canada] / 2t2.com
    Author : Gordon Black
    Contact : gordon@2t2.com
    Last Modified : April 27, 2005
    This script may be freely distributed as long as this header remains intact
    */

    // SETTINGS //
    // Config
    $dirUploads = "files/"; // The directory the files will be uploaded to
    $showDir = "yes";
    $numUploads = "10"; // Number of upload blanks to be shown on page
    $limitFiles = "yes"; // Allow only certain filetypes?
    $showAllowedFiles = "yes"; //
    $allowedFiles = array("jpg", "swf"); // Allowed filetypes
    $mainTableWidth = "75%";
    $stylesheet = "uploader_style.css";
    $showCopyright = "yes"; // not required, but the script IS FREE
    // Security
    $reqSecure = "yes"; // Passcode control?
    $userPassword = "2355";
    // Screen Text & Error Messages - can be changed to any language
    $caption = "MULTIFILE UPLOADER";
    $loginpageMsg = "A Passcode Is Required";
    $uploadpageMsg = "Select The Files To Upload";
    $passwordText = "Passcode :";
    $loginButtonText = "Go To Upload Page";
    $logoutText = "logout now";
    $allowedfiletypesText = "Allowed Filetypes";
    $lineText = "File";
    $uploadButtonText = "Upload Files";
    $statusText = "Upload Status :";
    $nofileText = "No file selected for upload";
    $notallowedText = "NOT ALLOWED";
    $existsText = "ALREADY EXISTS";
    $successText = "has been uploaded";
    // END OF SETTINGS //

    $pageTop = "<html><head><title>$caption</title><link href=$stylesheet rel=stylesheet type=text/css></head><body><div align=\"center\" class=caption>$caption</div>";

    $pre = "Multifile Uploader";
    $version = "2.0";
    $startdate = "2003";

    $copyright ="&nbsp;<p><div align=center class=copybar>$pre (v.$version) Copyright © $startdate - ". date ("Y")." <a href=http://www.2t2.com target=_new>Teletone [Canada] / 2t2.com</a></div>";

    $pageBottom = "</body></html>";

    // session management
    if($reqSecure == "yes") {
    session_start();
    if (!session_is_registered("mfupload")) {
    if (isset($_POST["password"]) && $_POST["password"] == $userPassword) {
    session_register("mfupload");
    $_SESSION["mfupload"] = $_POST["password"];
    header("Location: $PHP_SELF");
    exit;
    }
    else {
    // login page
    echo $pageTop;
    echo "&nbsp;<p><div align=\"center\" class=sitetag>$loginpageMsg</div>";
    echo "&nbsp;<p><div align=\"center\"><table border=0>";
    echo "<form name=loginform method=post action=$PHP_SELF>";
    echo "<tr><th>$passwordText</th><td><input type=password name=password style=\"width: 135px;\"></td>";
    echo "<th>&nbsp;</th><td><input type=submit class=button value=\"$loginButtonText\" style=\"width: 135px;\"></td></tr>";
    echo "</form></table></div>";
    echo "<script language=javascript>document.loginform.password.se lect();document.loginform.password.focus();</script>";
    if($showCopyright == "yes") {
    echo $copyright;
    }
    echo $pageBottom;
    exit;
    }
    }
    }

    // kill session
    if($_GET["action"]=="logout") {
    session_unset("mfupload");
    header("Location: $PHP_SELF");
    exit;
    }

    if($doupload) {
    global $allowedFiles;
    $num = 0;
    while($num < $numUploads) {
    $num++;

    $upFile = "dofile$num"."_name";
    $upFile1 = $$upFile;
    $upFile2 = "dofile$num";
    $upFile3 = $$upFile2;

    $ext = substr(strrchr( $upFile1 , "." ), 1);
    $ext = str_replace("jpeg", "jpg", $ext);

    $size = filesize($upFile3)/1024;
    $size = round($size,1);

    // error messages
    if($upFile3 == "") {
    $msg_upload .= "<tr><td>$lineText $num :</td><td colspan=2>$nofileText</td></tr>";
    }
    elseif($limitFiles == "yes" && !in_array($ext,$allowedFiles)) {
    $msg_upload .= "<tr><td>$lineText $num :</td><td><b>$upFile1</b></td><td>$notallowedText</td></tr>";
    }
    elseif(file_exists("$dirUploads/$upFile1")) {
    $msg_upload .="<tr><td>$lineText $num :</td><td><b>$upFile1</b></td><td>$existsText</td></tr>";
    }
    else {
    // everything OK
    move_uploaded_file ($upFile3, "$dirUploads/$upFile1");
    $msg_upload .="<tr><td>$lineText $num :</td><td><b>$upFile1</b> ($size)</td><td>$successText</td></tr>";
    }
    }
    }

    // upload page
    echo $pageTop;
    if ($reqSecure == "yes" && session_is_registered("mfupload")) {
    echo "<div align=\"right\"><a href=$PHP_SELF?action=logout>$logoutText</a>&nbsp;&nbsp;&nbsp;</div>";
    }
    echo "<div align=\"center\" class=sitetag>$uploadpageMsg</div>";
    echo "&nbsp;<p><div align=\"center\"><table width=$mainTableWidth border=\"0\" class=bodytable>";
    if($showAllowedFiles == "yes") {
    echo "<tr><th colspan=2><div align=\"center\">$allowedfiletypesText : ";
    for($i=0;$i<count($allowedFiles);$i++) {
    if (($i<>count($allowedFiles)-1))$commas=", "; else $commas="";
    list($key,$value)=each($allowedFiles);
    echo $value.$commas;
    }
    }
    echo "</div></td></tr>";
    echo "<tr><td width=50%><table width=100% border=0>";
    echo "<form enctype=\"multipart/form-data\" action=\"$PHP_SELF\" method=\"post\">";
    $num = 0;
    while($num < $numUploads) {
    $num++;
    echo "<tr><th style=\"width: 20%;\">$lineText $num:</td><td><input name=\"dofile$num\" type=\"file\" style=\"width: 100%;\"></td></tr> ";
    }
    echo "<tr><td style=\"width: 20%;\">&nbsp;</td><td><input name=\"doupload\" type=\"submit\" value=\"$uploadButtonText\" class=button style=\"width: 100%;\"></td></tr>";
    echo "</form>";
    echo "</table></td>";
    echo "<td width=50%><div align=\"center\"><table width=95% border=0 class=msg_table>";
    if($msg_upload) {
    echo "<tr><th colspan=3><div align=\"center\">$statusText ";
    if($showDir == "yes") {
    echo $dirUploads;
    }
    echo "</div></td></tr>";
    echo $msg_upload;
    }
    echo "</table></div></td></tr></table></div>";
    if($showCopyright == "yes") {
    echo $copyright;
    }
    echo $pageBottom;
    ?>


    How do I fix this? Please help I am going nuts!

  2. #2
    Product Designer keyone.it's Avatar
    Join Date
    Aug 2001
    Location
    Rome, Italy.
    Posts
    1,625
    Well, before freaking out, take a deap breath and read through the error message:

    Warning: move_uploaded_file(naturaltalent.cc/xml2/files//signed.jpg): failed to open stream: No such file or directory in /hsphere/local/home/naturalt/naturaltalent.cc/xml2/uploader.php on line 116

    First of all, the message points exactly at a line of code, this is already a HUGE help of the parser.
    Secondly, is there anything interesting the message gives you?

    Yes! Two things!

    1) The problem is about a path, because it cannot resolve the path you gave it.

    2) It actually shows you the path you are giving it, and at the first look it shows the problem, just look at the path itself for a moment:

    naturaltalent.cc/xml2/files//signed.jpg

    isn't there something strange?

    Yes! There are two consequent slashes! How is that possible? Let's give a look..
    The following is line 116, the incriminated code:

    move_uploaded_file ($upFile3, "$dirUploads/$upFile1");

    what is happening there, the move_uploaded_file function is called, passing two arguments: first a string with the path to the temporary uploaded file (which is held by the variable $upFile3). The second argument is a string, with the path to the final destination of the uploaded file, which is built from a path to the final directory (held by the variable $dirUploads) and a filename (held by the variable $upFile1).
    That part of code:

    "$dirUploads/$upFile1"

    which we car re-write, for clarity, in another style:

    $dirUploads . '/' . $upFile1

    Did you see that? Yes! WE are adding a slash there! But maybe the slash has been already added in the directory path (which is a pretty common mistake), which is held by $dirUploads. In that case we would get two consequent slashes!!!!

    Yey! Got it.
    Now you can either choose to cut out that slash right there on line 116, by replacing it with this:

    move_uploaded_file ($upFile3, "$dirUploads$upFile1");

    or (reccomended choise), you can correct your directory path declaration, which is at line 12, with this:

    $dirUploads = "files"; // The directory the files will be uploaded to




    In general, never go wild, chill out and help your parser help you. In PHP you get GREAT support from the parser when debugging (unlikely many other environments, like client-side scripting, as JavaScript, unfortunatelly).
    Usually all the information you need is right there! And it's pretty straightforward.
    Other times it's just a matter of back-solving problems, one step at a time.

    Obviously this is more difficult when you inherited a script rather than coded it yourself, because you don't have a clear layout of the procedure in your mind, so you have to go fishing...

    Hope this helps!
    Altruism does not exist. Sustainability must be made profitable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center